2016-10-03 4 views
0

В моем приложении у меня есть FloatingActionButton в ListFragment.ListFragment FloatingActionButton находится в неправильном положении

Вот макет ListFragment:

<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"> 

    <include layout="@android:layout/list_content"/> 

    <ListView 
     android:id="@id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <TextView 
     android:id="@id/android:empty" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="@string/no_contacts"/> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="16dp" 
     android:src="@drawable/ic_add" 
     app:layout_anchor="@id/android:list" 
     app:layout_anchorGravity="bottom|end" 
     android:layout_alignParentEnd="true"/> 
</android.support.design.widget.CoordinatorLayout> 

В Android Studio ФАБ находится в bottom-right положении, но когда я запускаю приложение, это в top-left.

ответ

0

Попробуйте использовать этот

<android.support.design.widget.FloatingActionButton 
android:id="@+id/fab" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="bottom|end" 
android:layout_margin="16dp" 
android:src="@drawable/ic_add" 
app:layout_anchor="@id/android:list" 
app:layout_anchorGravity="bottom|end" 
android:layout_alignParentBottom="true" 
android:layout_alignParentRight="true" 
/> 

0

Добавьте ListView и TextView в макете, который вы добавляете к этой схеме, используя включают тег.

0

Вот мой рабочий макет.

<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="match_parent"> 

    <include layout="@android:layout/list_content" /> 

    <ListView 
     android:id="@id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <TextView 
     android:id="@id/android:empty" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="no contacts" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="16dp" 
     android:src="@android:drawable/ic_input_add" 
     app:layout_anchor="@id/android:list" 
     app:layout_anchorGravity="bottom|end" /> 
</android.support.design.widget.CoordinatorLayout> 

И показ макета в устройстве довольно хорошо.

enter image description here

+0

В моем приложении ListFragment находится в ViewPager (Tabs), и это то, что я получаю: [ссылка] (http://i.imgur.com/F4hskOe.png) –

+0

Ища немного бит, если обнаружено, что фабрика должна быть помещена в основной макет мероприятия (в соответствии с рекомендациями руководства по материалам [здесь] (https://material.google.com/components/buttons-floating-action-button.html#buttons-floating -action-button-behavior) и как это сделать [здесь] (http://stackoverflow.com/questions/31596640/fab-animation-with-viewpager-tabslider/31663686#31663686) –

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