Android - Multi Columns ListView

邮差的信 提交于 2019-12-08 04:40:58

问题


I have an ArrayList<myObject> and a ListView with a personal ArrayAdapter<myObject> using an inflated View that generates a list of Buttons.

It works, but one button per line is quite layout consuming ^^

I wanted to know if it was possible to display two or more items (Button) per line and how to do such a thing ?

I thought about dividing my items in two lists (even and odd) but they'll have to scroll all-together for a better user experience...

any idea ? or object that already implements it ?

Thanks


回答1:


For that case, just take a GridView with 2 columns, i am sure this will fulfill your requirement.

gridview_row.xml

    <Button 
        android:text="Button" 
        android:id="@+id/button1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </Button>

</LinearLayout>

and take GridView instad of ListView as:

 <GridView 
        android:id="@+id/gridview01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:numColumns="2"
        android:horizontalSpacing="5dp"
        android:verticalSpacing="5dp">

 </GridView>

Once you are done with these 2 things, then implement the code in your custom adapter. And i am sure your current adapter is also 90% useful, you just need to change the code according the row xml file.



来源:https://stackoverflow.com/questions/7710642/android-multi-columns-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!