我想添加兩個按鈕 - 不喜歡在右上角。我可以做 ,完美的佈局,但如何動態地添加這兩個按鈕,我不知道 。 根據我的思維相對佈局是實現這種輸出的唯一方法。 如果有其他解決方案,請分享。
RelativeLayout
不是實現它的單一方法,但它是最有效的方法。例如,您可以將ImageView
包裝在FrameLayout
中,並將這兩個Buttons
放在水平線LinearLayout
中。然後,您將使用設置爲bottom|right
的layout_gravity
將LinearLayout
置於FrameLayout
中。但RelativeLayout
是要走的路,因爲您將避免在包裝容器和兩個Buttons
之間使用額外的佈局。對於RelativeLayout
你必須在佈局結束:
<RelativeLayout>
<ImageView width|height=fill_parent />
<Button width|height=wrap_content android="@+id/dislike"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />
<Button width|height=wrap_content android="@+id/like"
android:layout_toLeftOf="@id/dislike"
android:layout_alignParentBottom="true" />
</RelativeLayout>
如果你在代碼中添加Buttons
您將設置RelativeLayout.LayoutParams
爲Buttons
,並設置相應的規則,在XML佈局那些LayoutParams
。
*將兩個按鈕添加到所有這些方塊(「ImageViews」)或整個屏幕中,就像 - 在右角*中不喜歡的那樣?各爲 – Luksprog
。正如我在我的素描圖像中顯示的。所有圖像都會檢索表單網頁。所以用戶可以不喜歡任何圖像。我使用引用鏈接,它非常好,但是這兩個按鈕是我的額外要求。所以我很困惑如何做到這一點? –