底部对齐浮动操作按钮
Bottom Align Floating Action Button
我想对齐到我的 FAB 的右下角。
- 我试过
android:gravity="bottom|right"
- 当我尝试时
android:layout_alignParentBottom="true
" FAB
消失了
- 当我尝试时
android:layout_alignBottom="@id/lista_tiendas"
FAB
消失了
看似不复杂,但就是做不出来
有什么想法吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<ListView
android:id="@+id/lista_tiendas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:divider="@android:color/transparent"
android:dividerHeight="4.0sp"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_white_48dp"
app:backgroundTint="@color/spg_rosa"
app:borderWidth="0dp"
app:elevation="8dp"
app:fabSize="normal"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="@id/lista_tiendas"
/>
</RelativeLayout>
通过这样做,我能够让代码工作:
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="#ff0000"
app:borderWidth="0dp"
app:elevation="8dp"
app:fabSize="normal"
android:layout_alignLeft="@+id/text"
android:layout_above="@+id/text"/>
但是,它不适用于 below
而不是上面的 TextView
,我认为这可能是一个错误。
对于RelativeLayout
:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
... />
对于CoordinatorLayout
,你应该使用android:layout_gravity="end|bottom"
对于ConstraintLayout
:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
... />
有关详细信息,请参阅 。
FloatingActionButton 似乎没有正确定位在 RelativeLayout 中。
我把RelativeLayout改成了FrameLayout,问题解决了!
希望对您有所帮助!
<ListView
android:id="@+id/mylist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:divider="@android:color/transparent"
android:dividerHeight="1.0sp" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:src="@drawable/ic_add_white_48dp"
app:backgroundTint="@color/spg_rosa"
app:borderWidth="0dp"
app:elevation="8dp"
app:fabSize="normal" />
</FrameLayout>
布局应为 RelativeLayout。尝试下一个代码:
<RelativeLayout 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:id="@+id/ly_list_form"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="@+id/list_forms"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ly_bar_bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="right"
android:orientation="horizontal">
<android.support.design.widget.FloatingActionButton
android:id="@+id/button_addc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="28dp"
android:src="@drawable/ic_add"
app:borderWidth="0dp"
app:elevation="6dp"
app:pressedTranslationZ="12dp" />
</LinearLayout>
尝试
android:layout_gravity="bottom|right"
尝试使用 android.support.design.widget.CoordinatorLayout
,android:layout_gravity="bottom|right"
适合我。
在相对布局的底部和中心对齐按钮
将这两个添加到您的 floatingactionbutton 容器中
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
输出将是:
like this
我想对齐到我的 FAB 的右下角。
- 我试过
android:gravity="bottom|right"
- 当我尝试时
android:layout_alignParentBottom="true
"FAB
消失了 - 当我尝试时
android:layout_alignBottom="@id/lista_tiendas"
FAB
消失了
看似不复杂,但就是做不出来
有什么想法吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<ListView
android:id="@+id/lista_tiendas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:divider="@android:color/transparent"
android:dividerHeight="4.0sp"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_white_48dp"
app:backgroundTint="@color/spg_rosa"
app:borderWidth="0dp"
app:elevation="8dp"
app:fabSize="normal"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="@id/lista_tiendas"
/>
</RelativeLayout>
通过这样做,我能够让代码工作:
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="#ff0000"
app:borderWidth="0dp"
app:elevation="8dp"
app:fabSize="normal"
android:layout_alignLeft="@+id/text"
android:layout_above="@+id/text"/>
但是,它不适用于 below
而不是上面的 TextView
,我认为这可能是一个错误。
对于RelativeLayout
:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
... />
对于CoordinatorLayout
,你应该使用android:layout_gravity="end|bottom"
对于ConstraintLayout
:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
... />
有关详细信息,请参阅
FloatingActionButton 似乎没有正确定位在 RelativeLayout 中。
我把RelativeLayout改成了FrameLayout,问题解决了! 希望对您有所帮助!
<ListView
android:id="@+id/mylist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:divider="@android:color/transparent"
android:dividerHeight="1.0sp" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:src="@drawable/ic_add_white_48dp"
app:backgroundTint="@color/spg_rosa"
app:borderWidth="0dp"
app:elevation="8dp"
app:fabSize="normal" />
</FrameLayout>
布局应为 RelativeLayout。尝试下一个代码:
<RelativeLayout 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:id="@+id/ly_list_form"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="@+id/list_forms"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ly_bar_bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="right"
android:orientation="horizontal">
<android.support.design.widget.FloatingActionButton
android:id="@+id/button_addc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="28dp"
android:src="@drawable/ic_add"
app:borderWidth="0dp"
app:elevation="6dp"
app:pressedTranslationZ="12dp" />
</LinearLayout>
尝试
android:layout_gravity="bottom|right"
尝试使用 android.support.design.widget.CoordinatorLayout
,android:layout_gravity="bottom|right"
适合我。
在相对布局的底部和中心对齐按钮
将这两个添加到您的 floatingactionbutton 容器中
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
输出将是: like this