![](/img/trans.png)
[英][android]how to get 4 buttons at the bottom and each 2 button is beside each other
[英]how to layout two buttons beside each other with a gap in between
道歉,如果這似乎很明顯,但似乎無法正確解決。 我有兩個彼此相鄰的按鈕,而上傳按鈕實際上位於中間。 我真正想要的是這兩個按鈕之間的間距為10dp,我希望它們之間的間距位於中間。 我怎樣才能做到這一點?
<RelativeLayout
android:id="@+id/bak"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="10dp">
<Button
android:id="@+id/back_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="@string/button_back"
android:layout_toRightOf="@id/upload_button"
android:background="@drawable/love_heart"
android:textColor="@color/white"
android:padding="5dp"
android:textSize="10sp"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/upload_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="@string/button_upload"
android:background="@drawable/love_heart"
android:textColor="@color/white"
android:padding="5dp"
android:textSize="10sp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
使用以下視圖:
<RelativeLayout
android:id="@+id/bak"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="10dp">
<Button
android:id="@+id/back_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="@string/button_back"
android:layout_toRightOf="@id/view"
android:background="@drawable/love_heart"
android:textColor="@color/white"
android:padding="5dp"
android:textSize="10sp"
/>
<View
android:id="@+id/view"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_centerHorizontal="true"
/>
<Button
android:id="@+id/upload_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_toLeftOf="@id/view"
android:text="@string/button_upload"
android:background="@drawable/love_heart"
android:textColor="@color/white"
android:padding="5dp"
android:textSize="10sp"
/>
</RelativeLayout>
這是一個更好的解決方案。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="b1"
android:layout_weight=".5"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="b1"
android:layout_weight=".5"/>
</LinearLayout>
您可以根據需要添加填充...但是使用線性布局是處理此“問題”的一種簡單得多的更好方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.