是否有可能使ListView水平?我使用图库视图完成了此操作,但所选项目会自动出现在屏幕的中心。我不希望选中的项目位于我点击的同一位置。我该如何纠正这个问题?我的想法是用水平滚动来设置ListView。分享你的想法?


当前回答

当适配器中的数据涉及到另一个线程时,HorizontialListView不能工作。一切都100%在UI线程上运行。这是多线程中的一个大问题。我认为使用HorizontialListView不是解决你的问题的最佳方案。HorzListView是一个更好的方法。你只需用HorzListView替换你以前的画廊。您不需要修改关于适配器的代码。然后一切都会如你所愿。查看https://stackoverflow.com/a/12339708/1525777关于HorzListView。

其他回答

我在我的项目中使用了水平列表视图链接,我得到了很好的结果。我最初使用devsmart库,但它给了我一些问题。所以使用水平列表视图链接的最佳方式,因为它恢复了我的问题,而且我最近在谷歌PlayStore上使用这个库推出了我的应用程序,并得到了用户的良好响应。所以我建议你使用上面提到的相同的库来水平显示listview。享受:)

其实很简单: 简单地旋转列表视图躺在它的一边

mlistView.setRotation(-90);

然后在膨胀子对象时,它应该在getView方法中。你让孩子们站直:

 mylistViewchild.setRotation(90);

编辑: 如果你的ListView在旋转后不合适,把ListView放在这个RotateLayout中,就像这样:

 <com.github.rongi.rotate_layout.layout.RotateLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:angle="90"> <!-- Specify rotate angle here -->

    <ListView
       android:layout_width="match_parent"
       android:layout_height="match_parent">
    </ListView>
</com.github.rongi.rotate_layout.layout.RotateLayout>

对于我的应用程序,我使用一个包含LinearLayout的HorizontalScrollView,它的方向设置为水平。为了在里面添加图像,我在活动中创建ImageViews,并将它们添加到我的LinearLayout中。例如:

<HorizontalScrollView 
        android:id="@+id/photo_scroll"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:scrollbars="horizontal"
        android:visibility="gone">

        <LinearLayout 
            android:id="@+id/imageview_holder"
            android:layout_width="wrap_content"
            android:orientation="horizontal"
            android:layout_height="match_parent">

        </LinearLayout>
    </HorizontalScrollView>

这对我来说很好。在活动中,我所要做的就是下面的代码:

LinearLayout imgViewHolder = findViewById(R.id.imageview_holder);
ImageView img1 = new ImageView(getApplicationContext());
//set bitmap
//set img1 layout params
imgViewHolder.add(img1);
ImageView img2 = new ImageView(getApplicationContext());
//set bitmap
//set img2 layout params
imgViewHolder.add(img2); 

就像我说的,这对我来说很有用,我希望它也能帮助那些希望实现这一目标的人。

Paul没有费心去修复他的库中的bug或接受用户的修复。这就是为什么我建议另一个具有类似功能的库:

https://github.com/sephiroth74/HorizontalVariableListView

更新:2013年7月24日作者(sephiroth74)发布了基于android 4.2.2 ListView代码的完全重写版本。我必须说,它没有所有的错误,以前的版本有和伟大的工作!

这不是一个很好的答案,但是如何使用水平滚动视图呢?