我目前正在使用 android studio 創建一個應用程式,但在螢屏右下角放置按鈕時遇到問題。我選擇用一些組件填充相對布局,android:layout_marginRight="<x>dp"到目前為止,它已經使我能夠阻止視圖接觸邊緣。我成功使用它的示例如下所示(用于懸停在右上角的按鈕的 XML):
<RelativeLayout blah>
<com.google.android.material.button.MaterialButton
android:id="someID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:align_parentEnd="true"
android:layout_marginEnd="20dp"
android:layout_marginTop="20dp"
and so on describing the button but no more geometric statements
/>
</RelativeLayout>
但是,當我對添加線條android:layout_alignParentBottom和線條android:layout_marginBottom的按鈕執行相同操作時,底部邊距線無效并且按鈕粘在螢屏底部 - 這是冒犯者:
android studio 旁邊按鈕的 XML渲染。
請有人解釋為什么會發生這種情況以及如何解決它?我試圖在右下角放置一個按鈕,在它的右側和下方放置一個 20dp 的按鈕,以便它“懸停”在那里。
這是我的 XML 的其余部分,因為它目前是:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@ id/btn_add_review"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:paddingBottom="20dp"
android:clickable="true"
app:backgroundTint="@color/themeColorOrange"
app:srcCompat="@drawable/ic_baseline_add_24" />
</RelativeLayout>
uj5u.com熱心網友回復:
你可以簡單地把RelativeLayout周圍的FloatingActionButton,并給它padding的20dp是這樣的:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="wrap_content"
android:paddingBottom="20dp"
android:layout_height="wrap_content">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@ id/btn_add_review"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="20dp"
android:clickable="true"
app:backgroundTint="@color/themeColorOrange"
app:srcCompat="@drawable/ic_baseline_add_24" />
</RelativeLayout>
</RelativeLayout>
不幸的marginBottom是不能與alignParentBottom.
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/381923.html
標籤:安卓 按钮 android-相对布局 边距 底部
上一篇:使用javascript禁用按鈕
下一篇:CSS溢位:隱藏不適用于按鈕
