2017-01-23 4 views
0

Ich habe eine AppCompatActivity mit einem Listview mit dem Layout unterEmptyView von Listview versteckt BottomNavigationView

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/main_content" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/user_title" 
      android:background="@drawable/user_title_color" 
      android:textColor="@android:color/white" 
      android:textAppearance="@android:style/TextAppearance.Large"/> 
    <ListView android:id="@+id/joggings_list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:divider="#b5b5b5" 
     android:dividerHeight="1dp" 
     android:drawSelectorOnTop="false"/> 
     <LinearLayout 
      android:id="@+id/empty_list" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center_vertical|center"> 
      <TextView 
       android:text="No joggings yet" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
      <Button 
       android:id="@+id/empty_add_button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Add"/> 
     </LinearLayout> 
    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/add_jogging" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/bottom_navigation" 
     android:layout_alignParentRight="true" 
     android:layout_gravity="end|bottom" 
     android:layout_marginBottom="16dp" 
     android:layout_marginRight="16dp" 
     android:clickable="true" 
     android:src="@drawable/ic_plus" 
     app:borderWidth="0dp" /> 
     <android.support.design.widget.BottomNavigationView 
      android:id="@+id/bottom_navigation" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:background="@color/colorPrimaryDark" 
      android:foregroundTint="@color/colorAccent" 
      app:itemTextColor="@color/bottom_navigation_color" 
      app:itemIconTint="@color/bottom_navigation_color" 
      app:menu="@menu/bottom_navigation_main" /> 
</LinearLayout> 
</android.support.design.widget.CoordinatorLayout> 

und in meinem Code ich habe mListView.setEmptyView (findViewById (R.id.empty_list));

um eine Nachricht und eine Schaltfläche "Hinzufügen" anzuzeigen, wenn die Liste leer ist. Mein Problem ist, dass die BottomNavigationView ausgeblendet ist und der Benutzer nicht zu einer anderen Aktivität navigieren kann, wenn die Liste leer ist.
Eine mögliche Lösung, die ich mir vorstellen kann, ist das Hinzufügen einer anderen BottomNavigationView mit den gleichen Elementen im leeren Layout, aber das scheint hässlich.

Jede andere Lösung?

+0

Scheint ein Layout, um Problem zu sein, Ihre BottomNavigationView vom Bildschirm abgezogen, so dass eine mögliche Lösung eine relative Layout zu verwenden ist als direkte Schwester des Koordinators, um sicherzustellen, dass alle Ansichten auf den Bildschirm passen. –

Antwort

1

Set empty_list Höhe

+0

Dies funktioniert, aber Textfeld und Schaltfläche der leeren Liste werden am oberen Rand des Bildschirms angezeigt und die untereNavigationView wird direkt unter ihnen angezeigt. Ich würde gerne das leere Layout vertikal zentrieren und bottomNavigationView an den unteren Rand des Bildschirms anzeigen –

+0

android: layout_gravity = "center" hinzufügen – ChaitanyaAtkuri

1

Ihre ListView und es ist leer Blick auf wrap_content sollte das gleiche Layout haben Attribute, wenn Sie wollen, den gleichen Raum besetzen. In Ihrem Fall sollten sie beide

android:layout_width="match_parent" 
android:layout_height="0dp" 
android:layout_weight="1" 

Außerdem sollten Sie die FloatingActionButtonaußerhalb des LinearLayout setzen, sonst wird es die Größe Ihrer ListView/leeren Ansicht beeinflussen. Es soll auch ein direktes Kind von CoordinatorLayout sein, ansonsten funktionieren seine Standardverhalten nicht.

+0

Setzen FloatingActionButton als direkte Kind von CoordinatorLayout blendet einen Teil von FloatingActionButton unter BottomNavigationView –

+0

Überprüfen Sie ihre Ansichten. Außerdem schlage ich vor, entweder den FAB zu verschieben oder ihn vollständig zu entfernen, da der untere Bildschirmrand überladen ist, wenn Sie sowohl diesen als auch die BottomNavigationView haben. – Karakuri

0

Das folgende Layout funktionierte gut. Die Grundidee ist, dass coordinateLayout ListView und FloatingActionButton und leere Ansicht enthält. CoordinateLayout ist in einem äußeren vertikalen Linearlayout enthalten ist, die auch die Header-Textview enthält und die BottomNavigationView

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

    <TextView 
     android:id="@+id/user_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/user_title_color" 
     android:textAppearance="@android:style/TextAppearance.Large" 
     android:textColor="@android:color/white" /> 

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/main_content" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <ListView 
      android:id="@+id/joggings_list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:divider="#b5b5b5" 
      android:dividerHeight="1dp" 
      android:drawSelectorOnTop="false" /> 


     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/add_jogging" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/bottom_navigation" 
      android:layout_alignParentRight="true" 
      android:layout_gravity="end|bottom" 
      android:layout_marginBottom="16dp" 
      android:layout_marginRight="16dp" 
      android:clickable="true" 
      android:src="@drawable/ic_plus" 
      app:borderWidth="0dp" 
      app:layout_anchor="@id/joggings_list" 
      app:layout_anchorGravity="bottom|right|end" /> 


     <LinearLayout 
      android:id="@+id/empty_list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center_vertical|center" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="No joggings yet" /> 

      <Button 
       android:id="@+id/empty_add_button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Add" /> 
     </LinearLayout> 
    </android.support.design.widget.CoordinatorLayout> 

    <android.support.design.widget.BottomNavigationView 

     android:id="@+id/bottom_navigation" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:background="@color/colorPrimaryDark" 
     android:foregroundTint="@color/colorAccent" 
     app:itemIconTint="@color/bottom_navigation_color" 
     app:itemTextColor="@color/bottom_navigation_color" 
     app:menu="@menu/bottom_navigation_main" /> 
</LinearLayout> 
Verwandte Themen