我有一個可調整大小的應用部件。我想在圖片的上方和下方有文字。圖像應該佔用儘可能多的空間,文字應該直接放在圖像的上方和下方。可變父級大小的應用部件xml佈局
我只想在xml中做到這一點,但不能找出適用於所附圖像中顯示的兩種情況的佈局。
所以我的問題是,用什麼XML可以實現這種行爲?
編輯:圖像視圖可能比父容器視圖大。
我有一個可調整大小的應用部件。我想在圖片的上方和下方有文字。圖像應該佔用儘可能多的空間,文字應該直接放在圖像的上方和下方。可變父級大小的應用部件xml佈局
我只想在xml中做到這一點,但不能找出適用於所附圖像中顯示的兩種情況的佈局。
所以我的問題是,用什麼XML可以實現這種行爲?
編輯:圖像視圖可能比父容器視圖大。
事情是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="center"
android:layout_alignParentCenter="true"/>
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/imageview"
android:text="text 1"/>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/imageview"
android:text="text 2"/>
</RelativeLayout>
還是這個,使用佈局重來控制大小:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:weightSum="100"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_weight="10"
android:layout_height="0px"
android:text="text 1"/>
<ImageView
android:id="@+id/imageview"
android:layout_width="wrap_content"
android:layout_weight="80"
android:layout_height="0px"
android:scaleType="center"
android:layout_alignParentCenter="true"/>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_weight="10"
android:layout_height="0px"
android:text="text 2"/>
</LinearLayout>
播放使用權,影像對準和圖像比例鍵入以獲得它你想要的。
使用RelativeLayout和首先定義的圖像。在父級中使用中心對齊方式。然後是兩個textview,一個使用layoutAbove,另一個使用layoutBelow。 – Simon