2016-06-15 1 views
0

После установки setEmptyView кнопка, которая ранее была внизу, теперь поднимается до верхней части макета. Пожалуйста, помогите мне понять, почему. Вот мой код:Кнопка теперь находится в верхней части после установки 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

Refresh Кнопка должна быть в нижней не на верхней.

Любая идея?

+0

попытка изменить 'андроида: layout_height = "wrap_content"' 'для Android: layout_height = "0dp"' 'в вашем ListView' –

+0

@ PhanVănLinh, я попробовал это, но я не могу видеть пустое изображение. –

ответ

1

Использование RelativeLayout в activity_list.xml, а также и положить

alignParentBottom="true" 

в Button теге

+0

Возможно, вы захотите поместить 'alignParentTop = "true" в ListView и' alignAbove = "buttonID" ' –

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> 
+0

Кнопка не должна находиться в Activity_list_empty. Существует определенная причина, по которой я размещаю эту кнопку там. –

+0

Нужно ли вам это показывать, только если список пуст? –

Смежные вопросы