[英]Bottom Align Floating Action Button
I want to align to bottom right my FAB.我想与我的 FAB 右下角对齐。
android:gravity="bottom|right"
android:gravity="bottom|right"
android:layout_alignParentBottom="true
" FAB
disappearsandroid:layout_alignParentBottom="true
" FAB
消失android:layout_alignBottom="@id/lista_tiendas"
FAB
disappearsandroid:layout_alignBottom="@id/lista_tiendas"
FAB
消失It doesn't seem complicated but I just can't accomplish it看起来并不复杂,但我就是做不到
Any Ideas?有任何想法吗?
<?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>
For RelativeLayout
:对于
RelativeLayout
:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
... />
For CoordinatorLayout
, you should use android:layout_gravity="end|bottom"
对于
CoordinatorLayout
,你应该使用android:layout_gravity="end|bottom"
For ConstraintLayout
:对于
ConstraintLayout
:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
... />
See this answer for more information.有关更多信息,请参阅此答案。
Layout should be RelativeLayout .布局应该是RelativeLayout 。 Try the next code:
尝试下一个代码:
<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>
It appears that FloatingActionButton isn't positioned correctly inside a RelativeLayout.似乎 FloatingActionButton 在 RelativeLayout 中的位置不正确。
I changed RelativeLayout to FrameLayout, and problem solved!我把RelativeLayout改成了FrameLayout,问题解决了! Hope it helps!
希望能帮助到你!
<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>
尝试使用android.support.design.widget.CoordinatorLayout
和android:layout_gravity="bottom|right"
对我android:layout_gravity="bottom|right"
。
I was able to get the code to work by doing this:通过这样做,我能够使代码正常工作:
<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"/>
However, it didn't work with below
the TextView
instead of above, I believe it could be a bug.但是,它不适用于
TextView
below
而不是上方,我相信这可能是一个错误。
Try尝试
android:layout_gravity="bottom|right"
android:layout_gravity="底部|右"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.