我正在使用一个简单的ListView
,其中每个项目只包含文本字段而没有其他内容。 下面是列表项我的XML代码:Android如何使列表项高度增加以容纳内容
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="@drawable/bg_card">
<TextView
android:id="@+id/txt"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:textSize="15sp"
android:paddingLeft="6dip"
android:textColor="#878787"
android:textIsSelectable="true"/>
</LinearLayout>
</FrameLayout>
这里是我使用列表视图中的片段布局。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e5e5e5">
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:dividerHeight="0dp"
android:divider="@null"/>
</RelativeLayout>
现在,虽然在我的片段像这样
Level weather_data[] = new Level[] {
new Level(R.drawable.s1,
"Some text which will be present in the list item",
R.drawable.play_button)
};
创建适配器的对象。如果我有即文本的第二个参数很长的句子,它的某些部分没有得到显示并且该句子在列表项中不完整地显示。
我已经尝试使用android:minHeight
来更改列表项的高度,但它不起作用。有什么可以解决这个问题的? 谢谢
我想这是因为你给TextView的高度50dp.Make它WrapContent采取文字的大小。 –
@ user2012不,它仍然没有任何区别。 –
试试这个http://stackoverflow.com/questions/5033012/auto-scale-textview-text-to-fit-within-bounds – VikramV