2

我在使用标准 android listview 时遇到问题。如果文本要长时间显示在我想要的一个列表视图项目中,则该项目会自行放大。

这是它现在的样子的截图: http ://www.abload.de/image.php?img=unbenanntdjupi.png

我也在使用另一个带有自定义布局的列表视图,这没问题:列表视图项目会自行扩大。

仅供参考:我正在使用 actionbarsherlock,所以我从“SherlockListActivity”扩展了我的活动。

我希望你们中的一个可以帮助我......因为在这种情况下实现自定义列表视图是一个巨大的开销:/

提前致谢!

// 编辑:这是标准的“simple_list_item_single_choice”...实际上我不想自定义它。

<?xml version="1.0" encoding="utf-8"?>    
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/listPreferredItemHeightSmall"
        android:textAppearance="?android:attr/textAppearanceListItemSmall"
        android:gravity="center_vertical"
        android:checkMark="?android:attr/listChoiceIndicatorSingle"
        android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
        android:paddingRight="?android:attr/listPreferredItemPaddingRight"
    />

这是我如何将其添加到我的布局的代码:

    <ListView 
        android:id="@id/android:list"
        android:layout_height="0dip"
        android:layout_width="fill_parent"
        android:layout_weight="1" />

// 在实现 iturki 的答案后进行编辑:它解决了 android 4.x 的问题,但不适用于 android 级别 10 的设备。

例外:

08-30 14:25:04.049: E/AndroidRuntime(843): FATAL EXCEPTION: main
08-30 14:25:04.049: E/AndroidRuntime(843): android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.CheckedTextView
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.LayoutInflater.createView(LayoutInflater.java:518)
08-30 14:25:04.049: E/AndroidRuntime(843):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.AbsListView.obtainView(AbsListView.java:1430)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.ListView.makeAndAddView(ListView.java:1745)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.ListView.fillDown(ListView.java:670)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.ListView.fillFromTop(ListView.java:727)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.ListView.layoutChildren(ListView.java:1598)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.AbsListView.onLayout(AbsListView.java:1260)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.View.layout(View.java:7175)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.View.layout(View.java:7175)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.View.layout(View.java:7175)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.View.layout(View.java:7175)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.View.layout(View.java:7175)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.View.layout(View.java:7175)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.View.layout(View.java:7175)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.os.Looper.loop(Looper.java:123)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.app.ActivityThread.main(ActivityThread.java:3683)
08-30 14:25:04.049: E/AndroidRuntime(843):  at java.lang.reflect.Method.invokeNative(Native Method)
08-30 14:25:04.049: E/AndroidRuntime(843):  at java.lang.reflect.Method.invoke(Method.java:507)
08-30 14:25:04.049: E/AndroidRuntime(843):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-30 14:25:04.049: E/AndroidRuntime(843):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-30 14:25:04.049: E/AndroidRuntime(843):  at dalvik.system.NativeStart.main(Native Method)
08-30 14:25:04.049: E/AndroidRuntime(843): Caused by: java.lang.reflect.InvocationTargetException
08-30 14:25:04.049: E/AndroidRuntime(843):  at java.lang.reflect.Constructor.constructNative(Native Method)
08-30 14:25:04.049: E/AndroidRuntime(843):  at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.LayoutInflater.createView(LayoutInflater.java:505)
08-30 14:25:04.049: E/AndroidRuntime(843):  ... 42 more
08-30 14:25:04.049: E/AndroidRuntime(843): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.view.View.<init>(View.java:1957)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.TextView.<init>(TextView.java:344)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.CheckedTextView.<init>(CheckedTextView.java:58)
08-30 14:25:04.049: E/AndroidRuntime(843):  at android.widget.CheckedTextView.<init>(CheckedTextView.java:54)
08-30 14:25:04.049: E/AndroidRuntime(843):  ... 45 more

我认为这些是最重要的几点:

android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.CheckedTextView
...
Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
4

1 回答 1

2

改变:

android:layout_height="?android:attr/listPreferredItemHeightSmall"

到:

android:layout_height="wrap_content"

这将使您的列表行扩展以适合其内容。

于 2012-08-30T11:41:42.033 回答