我有一个可调整大小的应用部件。我想在图片的上方和下方有文字。图像应该占用尽可能多的空间,文字应该直接放在图像的上方和下方。可变父级大小的应用部件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