Android ListView/ListFragment强制单行(Java代码)

Android ListView/ListFragment强制单行(Java代码),android,android-listview,android-fragments,android-listfragment,Android,Android Listview,Android Fragments,Android Listfragment,我似乎找不到解决这个被认为很简单的问题/bug的方法,所以这里是: 类型为(android.R.layout.simple_list_item_checked)的ListFragment,单击它时,将加载其他片段并执行其他工作 问题是ListFragment中不在视图中的字符串在滚动回视图时会毫无明显原因地“包装”到下一行。下面的照片更能说明问题: 照片1:正常状态 照片2:列表向下滚动-一切正常(兰博基尼不在视野内) 照片3:但是当我选择保时捷并向下滚动时,“野马”文本被破坏了

我似乎找不到解决这个被认为很简单的问题/bug的方法,所以这里是:

类型为(android.R.layout.simple_list_item_checked)的ListFragment,单击它时,将加载其他片段并执行其他工作

问题是ListFragment中不在视图中的字符串在滚动回视图时会毫无明显原因地“包装”到下一行。下面的照片更能说明问题:


照片1:正常状态


照片2:列表向下滚动-一切正常(兰博基尼不在视野内)


照片3:但是当我选择保时捷并向下滚动时,“野马”文本被破坏了


照片4:“兰博基尼”也一样,在一些随机点击后被卷回


我用来创建listview的代码非常简单:

 @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);
        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        getListView().setHorizontalFadingEdgeEnabled(true);
        getListView().setVerticalFadingEdgeEnabled(true);
        getListView().setFastScrollEnabled(true);
        carsTitleAdapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_list_item_checked, CarModels.Models);
        setListAdapter(carsTitleAdapter);
我尝试在onListItemClick()的末尾调用notifyDataSetChanged(),希望它能刷新列表,但问题仍然存在。有什么可能的解决办法吗?谢谢


PS:我在Galaxy Tab 10.1、Honeycomb 3.1和support-library-v4上运行它。这可能是此版本上的错误吗?

我通过重写onCreateView并在方法返回的视图中传递一个布局文件,该文件包含一个带有android=“@android:id/list”的ListView,从而解决了这个问题

        @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        return inflater.inflate(R.layout.list_fragment_layout, null);
    }

list_fragment_layout.xml:

    <?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="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>


我会尝试删除
getListView().setHorizontalFadingEdgeEnabled(true)。我不确定这是否会改变什么,但你不应该需要它。我无法复制它。我已经在Galaxy Nexus(4.0.2)和Nexus S(2.3.6使用支持库)上试过了,对我来说效果很好。@PedroLoureiro即使我删除了这个bug,它仍然存在。@PaulDrummond嗯。也许这是蜂巢3.1中带有支持库的bug。这对我来说解决不了。我的列表视图已在布局中定义。
    <?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="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>