我完全用XML创建我的布局。我希望显示ListView
,并且屏幕底部始终有一个按钮,就像默认的FullScreenActivity一样。但是,问题是位于底部的按钮也出现在屏幕顶部。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff000000"
tools:context=".ChannelNameActivity">
<ListView
android:id="@+id/channelListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/black_overlay"
android:orientation="horizontal"
tools:ignore="UselessParent">
<Button
android:id="@+id/dummy_button"
style="?metaButtonBarButtonStyle"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/dummy_button" />
</LinearLayout>
</RelativeLayout>
答案 0 :(得分:0)
您必须在ListView中使用android:layout_above="@+id/lnlLayout"
属性,在LinearLayout上使用android:alignParentBottom="true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff000000"
tools:context=".ChannelNameActivity">
<ListView
android:id="@+id/channelListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/lnlLayout"
android:keepScreenOn="true"/>
<LinearLayout
android:id="@+id/lnlLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/black_overlay"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
tools:ignore="UselessParent">
<Button
android:id="@+id/dummy_button"
style="?metaButtonBarButtonStyle"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/dummy_button" />
</LinearLayout>
</RelativeLayout>
答案 1 :(得分:0)
(OP上一个问题的代码说明:ArrayAdapter unable to update contents)
因为在onCreate()
中您将活动布局作为标题视图添加到ListView,这是不必要的(不是必需的)。
所以只需从onCreate()
final View contentView = (View)getLayoutInflater().inflate(R.layout.activity_channelname, null);
channelListView.addHeaderView(contentView);