[英]Align a button to the bottom right of screen?
我在“操作”按鈕的右側有一個提交按鈕:
我試過使用代碼:
android:gravity="bottom|right"
但它不起作用,並且仍然停留在同一位置。
我的完整代碼是這樣的:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:keepScreenOn="true"
android:textSize="25dp"
android:padding="30dp"
android:textStyle="bold"
android:textAlignment="center"
android:text="@string/select_action"
android:id="@+id/btnSelectPhoto"
android:layout_alignParentBottom="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/btnSelectPhoto"
android:keepScreenOn="true"
android:gravity="bottom|right"
android:padding="30dp"
android:text="@string/submit"
android:textSize="25dp"
android:textStyle="bold"
android:id="@+id/btnSubmit"
android:layout_alignParentBottom="true"
/>
即使使用上面的代碼,布局仍然與圖像相同。 我怎樣才能解決這個問題?
修復:由於Egor N,添加了android:layout_alignParentRight =“ true”。
android:layout_alignParentRight="true"
應該可以完成這項工作。 但是,您應該擺脫android:layout_toRightOf="@id/btnSelectPhoto"
。
android:gravity
不起作用,因為此值應用於視圖內的內容(按鈕內的文本)。
您可以在兩個波頓之間使用simlpe視圖
例如:
<LinearLayout
android:orientation="horizontal"
android:weightSum="3"
android:layout_width="match_parent"
android:layout_height="80dp"
>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.