[英]How to achieve layout for given screen in Android?
我嘗試了Framelayout
, LinearLayout
和RelativeLayout
的許多Framelayout
,但對如何在Android中實現以下屏幕布局Framelayout
。
因此,讓我們進入LinearLayout
。
[![在此處輸入圖片描述] [1]] [1]
TextView
,可以看到Manhattan, NY
ImageView
,我們可以看到心和數量。 Drable
行的簡單文本。 我能夠使用LinearLayout
和Bitmap
添加心形圖像來獲得前兩個部分。
如何實現Third section
? 我需要LinearLayout
或FrameLayout
嗎?
我得到的是第三部分是placeholder
,在其中我們設置了背景色並添加了兩個圖像。 對?
什么是實現整體布局的最佳選擇?
您需要最靈活的RelativeLayout-您只能使用它進行第3節並將其嵌套到LinearLayout
或者只用一個RelativeLayout
進行整個布局(盡管后一種選項對於按比例划分可用空間不是很好,輕松使用帶LinearLayout
重的LinearLayout
)
只是為了補充Ivan的答案,對於Android XML,您必須執行與基於表的設計類似的操作。
您可以使用http://developer.android.com/guide/topics/ui/layout/relative.html作為對RelativeLayout和http://developer.android.com/guide/所允許執行的所有操作的參考topic / ui / layout / linear.html作為使用LinearLayout的參考。
但是一般
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="0dp"
android:layout_height="24sp"
android:layout_weight="0.33"
/>
<TextView
android:layout_width="0dp"
android:layout_height="24sp"
android:layout_weight="0.33"
/>
<TextView
android:layout_width="0dp"
android:layout_height="24sp"
android:layout_weight="0.33"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/example.png"
android:id="@+id/exampleImage"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="24sp"
android:layout_alignLeft="@id/exampleImage"
android:layout_alignRight="@id/exampleImage"
android:layout_alignBottom="@id/exampleImage"
android:background="#80808080"
android:text="on image label"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="24sp"
android:layout_alignLeft="@id/exampleImage"
android:layout_alignRight="@id/exampleImage"
android:layout_below="@id/exampleImage"
android:background="#FF808080"
android:text="below image caption"
/>
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.