我想把地圖的縮放控制放在屏幕的右下角。我可以使用RelativeLayout同時使用alignParentBottom="true"
和alignParentRight="true"
,但使用Framelayout,我沒有找到任何這樣的屬性。我如何將它與屏幕的右下角對齊?Android:使用FrameLayout將按鈕對齊到屏幕的右下角?
回答
其實這是可能的,儘管什麼在其他的答案說來實現。如果您有FrameLayout
,並且想要將子項目放在最下方,則可以使用android:layout_gravity="bottom"
,這將使該子項與FrameLayout
的底部對齊。
我知道它的作品,因爲我使用它。我知道已經晚了,但它可能會來方便別人,因爲這排名前位置上的谷歌
你不能用FrameLayout來做到這一點。
從規格:
http://developer.android.com/reference/android/widget/FrameLayout.html
「的FrameLayout被設計來阻擋屏幕顯示單個項目上的一個區域,您可以將多個孩子去的FrameLayout增加,但所有的孩子都盯住屏幕左上角。「
爲什麼不使用RelativeLayout?
我想要一個列表顯示在左側,重疊地圖。哦,這可能與RelativeLayout不是嗎?好,謝謝。 – 2010-11-09 03:28:08
「但所有的孩子都固定在屏幕的左上方」 - 不一定是屏幕的頂部,你可以將它對齊到右邊,底部等等嗎? – 2010-11-09 03:30:31
是的,這是可能的RelativeLayout。您可以在彼此頂部佈局視圖。 – Juhani 2010-11-09 19:01:31
它可以通過RelativeLayout
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:src="@drawable/icon"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
如果在'RelativeLayout'中使用'wrap_content',這是行不通的。因爲無論如何,RelativeLayout在整個屏幕上縮放。 – 2013-12-20 20:03:55
我也遇到了這種情況,並想出瞭如何使用做FrameLayout裏。 以下輸出由以下代碼生成。
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/contactbook_icon"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="140"
android:textSize="12dp"
android:textColor="#FFFFFF"
android:layout_gravity="bottom|right"
android:layout_margin="15dp" />
</FrameLayout>
變化幅度值,以調整在圖像的文本位置。刪除保證金可能會使文本有時不在視圖中。
最好的答案......謝謝,解決了長久以來的謎團。 – YvesLeBorg 2017-04-08 14:35:02
設置已android:layout_gravity="bottom|right"
工作對我來說
兩種方法可以做到這一點:
1)使用的幀結構
android:layout_gravity="bottom|right"
2)使用相對佈局
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
你可以添加一個不可見的TextView到FrameLayout。
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="invisible"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<Button
android:id="@+id/daily_delete_btn"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:text="DELETE"
android:layout_gravity="center"/>
<Button
android:id="@+id/daily_save_btn"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:text="SAVE"
android:layout_gravity="center"/>
</LinearLayout>
如果您想嘗試使用Java代碼。你去 -
final LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
yourView.setLayoutParams(params);
params.gravity = Gravity.BOTTOM; // set gravity
- 1. 將一個按鈕對齊屏幕的右下角?
- 2. 對齊屏幕右下角的按鈕離線html
- 3. 將按鈕對齊到屏幕底部
- 4. 無法將按鈕對齊屏幕左下角 - 反應本地
- 5. 角MD按鈕右對齊
- 6. Android - 右側屏幕按鈕
- 7. 如何將此按鈕對齊屏幕右側?
- 8. 如何在android的左上角和右下角左右對齊按鈕?
- 9. Android對齊關閉按鈕到對話框的右上角?
- 10. 對齊按鈕到屏幕底部
- 11. 使用css將SVG粘貼到屏幕的右下角
- 12. 如何將一組按鈕與屏幕的底部對齊android
- 13. 如何將按鈕對齊到LinearLayout的最右角?
- 14. Libgdx將位圖字體對齊屏幕的右上角
- 15. 對齊按鈕,屏幕的LinearLayout的BUTTOM
- 16. 如何將按鈕對齊到右側?
- 17. 將中央按鈕對齊到屏幕底部
- 18. 如何將按鈕對齊到屏幕底部
- 19. 如何對齊pyqt右下角的按鈕?
- 20. UITableView單元格對齊不對齊到屏幕的右側
- 21. 屏幕角落的按鈕
- 22. Android:在按鈕的右上角對齊圖像
- 23. 對齊屏幕的底部下方的按鈕
- 24. 顯示按鈕右側對齊下面
- 25. Android:圖像按鈕沒有右對齊
- 26. 中心右對齊按鈕 - Android
- 27. android按鈕右對齊旋轉-90度
- 28. MapFragment右下角的按鈕
- 29. 右對齊按鈕垂直未對齊
- 30. ListView將按鈕按下屏幕
嗨byte1918,如果您認爲這不是問題的正確答案,那麼您應該非常歡迎 - 並且我認爲這對每個人都有用 - 如果您發佈了正確的解決方案。或者至少解釋是什麼讓這是一個錯誤的答案。謝謝。 – lblasa 2012-09-28 16:13:24
要對齊右下角,可以使用android:layout_gravity =「bottom | right」 – 2013-09-23 00:13:04
如果它不能立即反映在預覽中,請嘗試從設計選項卡中進行設置。通常工作, – yUdoDis 2015-07-15 18:31:49