Android set the GridView to have 2 columns per row only

前端 未结 2 1011
别那么骄傲
别那么骄傲 2020-12-15 04:28

Here is my code in my Activity:

public class GridViewActivity extends Activity {

    GridView gridView;

    static final String[] MOBILE_OS = new String[]          


        
相关标签:
2条回答
  • 2020-12-15 04:45

    Use the android:numColumns="2" in your GridView widget

    <?xml version="1.0" encoding="utf-8"?>
    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/grid"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:numColumns="2"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        android:scrollbarStyle="outsideOverlay"
        android:verticalScrollbarPosition="right"
        android:scrollbars="vertical">
    </GridView>
    

    You can get familiar with Android UI in this link.Try to focus on the GridView Topic

    0 讨论(0)
  • 2020-12-15 04:56

    you can also set number of columns by programmatically in a GridView in following way:-

     gridview.setNumColumns(n);
    

    where 'n' is the number of columns.

    0 讨论(0)
提交回复
热议问题