具有灵活高度的ListView中的Android自定义行布局
嗨,我正在尝试创建一行,如下所示: 该行应具有灵活的高度,如果字幕文本较长,则该行应变得更高。 左侧的绿色视图也应增大,以填充行的整个高度。 行高应仅根据文本(标题+副标题)确定 这是我创建的布局:具有灵活高度的ListView中的Android自定义行布局,android,android-layout,android-listview,android-linearlayout,android-view,Android,Android Layout,Android Listview,Android Linearlayout,Android View,嗨,我正在尝试创建一行,如下所示: 该行应具有灵活的高度,如果字幕文本较长,则该行应变得更高。 左侧的绿色视图也应增大,以填充行的整个高度。 行高应仅根据文本(标题+副标题)确定 这是我创建的布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<View
android:id="@+id/is_in_range_view"
android:layout_width="15dip"
android:layout_height="fill_parent"
android:background="#99CC00" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="@+id/row_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="5dip"
android:text="@string/title"
android:textSize="16sp" />
<TextView
android:id="@+id/row_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginLeft="10dip"
android:text="@string/subtitle"
android:textSize="12sp" />
<View
style="@style/SeparatorLine"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_marginTop="5dip" />
</LinearLayout>
</LinearLayout>
但我得到的结果是:
显然视图布局高度属性的fill\u parent
值有问题,但这正是我想要的!
我只希望行高度将基于文本,而不是绿色视图
我该怎么做?好的,问题是我在存放两个
文本视图的内部线性布局中为布局高度
输入了错误的值。
它被设置为fill\u parent
,而不是wrap\u content
一旦设置为wrap\u content
一切正常
正确的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<View
android:id="@+id/is_in_range_view"
android:layout_width="15dip"
android:layout_height="fill_parent"
android:background="#99CC00" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="@+id/row_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="5dip"
android:maxLines="1"
android:text="@string/title"
android:textSize="16sp" />
<TextView
android:id="@+id/row_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginLeft="10dip"
android:maxLines="3"
android:text="@string/subtitle"
android:textSize="12sp" />
<View
style="@style/SeparatorLine"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_marginTop="5dip" />
</LinearLayout>
好的,问题是我在存放两个文本视图的内部线性布局
中为布局高度
输入了错误的值。
它被设置为fill\u parent
,而不是wrap\u content
一旦设置为wrap\u content
一切正常
正确的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<View
android:id="@+id/is_in_range_view"
android:layout_width="15dip"
android:layout_height="fill_parent"
android:background="#99CC00" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="@+id/row_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="5dip"
android:maxLines="1"
android:text="@string/title"
android:textSize="16sp" />
<TextView
android:id="@+id/row_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginLeft="10dip"
android:maxLines="3"
android:text="@string/subtitle"
android:textSize="12sp" />
<View
style="@style/SeparatorLine"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_marginTop="5dip" />
</LinearLayout>
为什么有最外层的线性布局?这似乎是多余的,因为它的独生子女是另一个直系亲属。@Sam sorty你说得对。固定的。但是它仍然不能解决这个问题,为什么你有最外层的线性布局?这似乎是多余的,因为它的独生子女是另一个直系亲属。@Sam sorty你说得对。固定的。但它仍然不能解决这个问题