【发布时间】:2012-09-19 23:01:41
【问题描述】:
我需要一些帮助来将自定义列表视图与图像和文本对齐。
我正在尝试这个:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center"
android:paddingTop="20dp"
android:layout_weight="2"
android:text="TextView" />
</LinearLayout>
而且我认为 weight 是保持元素的比例,而不是元素的内容,但显然它关心文本视图内部的东西,所以我的列表看起来很乱。
无论文本在文本视图中多长时间,如何对齐使其相同?
所以无论右手边的文字如何,绿线都应该是垂直的直线。
Tnx
【问题讨论】:
-
您是否尝试过使用“简单”文本视图并将图像添加为最左侧的复合可绘制对象?可绘制的边界可以(并且必须,除非您使用固有尺寸)设置为您所需的 50dp。在这种情况下,文本视图应该填充父视图,并以 c 的重力为中心。
-
我在几个地方使用了自定义适配器,所以我没有尝试将所有内容都放在简单的文本视图中。
标签: android android-layout alignment