How to split Linear Layout in to two columns?

后端 未结 3 410
青春惊慌失措
青春惊慌失措 2020-12-31 11:04

I have to split a Single Linear layout into a Two Columns(Like newspaper Columns).The linear layout contain text-view and image-vie

3条回答
  •  猫巷女王i
    2020-12-31 11:17

    You can't do it with GridView. You would have to create a custom view to do this.

    if you know how big your grid items are, you can cut some corners. GridView is complicated mostly because it deals with items of any size and loads them dynamically. An easier way for you might be:

    1.Create a HorizontalScrollView with a horizontal LinearLayout inside.

    2.Determining how many rows of your item will fit on the screen. Call this rows.

    3.while you still have items you need to layout:

        1.Create a vertical LinearLayout, adding rows or less items to it.
        2.Add your new vertical LinearLayout to the horizontal one.
    

    There are some downsides versus what a "horizontal GridView" would get you:

    1.All the views are loaded up immediately, which is bad for huge lists of items.
    2.You need to know how big your items are, and they need to be the same size.
    

    Upsides:

    1.It's very easy to implement.
    

    for more inf plz see this link

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        ScrollView scrollView = new ScrollView(this);//ScrollView
        LinearLayout ll = new LinearLayout(this); //root LinearLayout
        ll.setOrientation(LinearLayout.HORIZONTAL);//with horizontal orientation
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT,1f);
        LinearLayout l2 = new LinearLayout(this); //sub linearlayout
        l2.setOrientation(LinearLayout.VERTICAL);//with vertical orientation
        l2.setLayoutParams(layoutParams);
        LinearLayout l3 = new LinearLayout(this); //sub linearlayout
        l3.setOrientation(LinearLayout.VERTICAL);//with vertical orientation
        l3.setLayoutParams(layoutParams);
        int totalvalues=41;     //i take count as 41
        for(int i=0;i

提交回复
热议问题