【发布时间】:2014-06-28 09:11:48
【问题描述】:
我尝试将 TextView 添加到自定义活动以在多个活动中显示,但没有显示任何内容。 这是我的自定义活动代码:
LinearLayout layout;
public void SetupFooter() {
layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setGravity(android.view.Gravity.BOTTOM|android.view.Gravity.CENTER_HORIZONTAL);
TextView tv = new TextView(this);
tv.setText("abc");
layout.addView(tv);
}
这是我想要添加页脚的 main_activity xml 代码:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageButton
android:id="@+id/btnGoToTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_margin="5dip"
android:background="@drawable/buttongototop"
android:padding="5dip"
android:visibility="gone" />
</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:text="TextView" />
</LinearLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white"
android:choiceMode="singleChoice"
android:headerDividersEnabled="false" />
<ListView
android:id="@+id/right_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/white"
android:choiceMode="singleChoice"
android:headerDividersEnabled="false" />
</android.support.v4.widget.DrawerLayout>
当我在扩展活动中调用 SetupFooter() 时,没有显示任何内容。 我的代码有问题吗? 抱歉我的英语不好,谢谢你帮助我!
编辑: 我添加了这个: addContentView(layout, new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 现在显示了,但没有放在底部,怎么让它留在底部?
【问题讨论】:
标签: android