设置setEmptyView后,按钮现在处于TOP状态

时间:2016-06-15 08:14:12

标签: android empty-list

设置setEmptyView后,之前位于底部的按钮现在上升到布局顶部。请帮我弄清楚原因。这是我的代码:

activity_list.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="top|center"
    android:orientation="vertical" >

    <ListView
          android:id="@+id/listview_snyc"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="1">
    </ListView>

    <Button
        android:id="@+id/button_refresh"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="30dp"
        android:paddingRight="30dp"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:gravity="center"
        android:text="Sync" />

</LinearLayout>

activity_list_empty.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageview_empty"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/empty" />

</RelativeLayout>

Java代码:

list = (ListView) findViewById(R.id.listview_snyc);
list.setAdapter(new MasterFileMenuAdapter(this,data));

View emptyView = getLayoutInflater().inflate(R.layout.activity_list_empty, null);
addContentView(emptyView, list.getLayoutParams());
list.setEmptyView(emptyView);

每当ListView为空时,我都会得到以下结果:

enter image description here

刷新按钮应位于顶部,而不是顶部

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

同时在RelativeLayout中使用activity_list.xml并输入

alignParentBottom="true"
<{1}}标记

中的

答案 1 :(得分:0)

将按钮移动到空视图并将其对齐到底部:
activity_list.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="top|center"
    android:orientation="vertical" >

<ListView
      android:id="@+id/listview_snyc"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1">
</ListView>



</LinearLayout>

activity_list_empty.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageview_empty"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/empty" />

 <Button
        android:id="@+id/button_refresh"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="30dp"
        android:paddingRight="30dp"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:gravity="center"
        android:layout_alignParentBottom="true"
        android:text="Sync" />

</RelativeLayout>
相关问题