如何将线性布局拆分为两列?

Shr*_*a S 12 android android-linearlayout

我必须将单线性布局拆分为两列(如报纸列).线性布局包含文本视图图像视图

我已经占据了屏幕宽度,并将其分成了一半,TextView然后ImageView进入第一列,即下图中的A B C 块.现在剩下的TextView并且' ImageView必须转到下一列,D E F就像它继续下去一样那么如果有人给我任何代码或想法来实现这个将是有帮助的..我尝试过GridView哪个不适合我的问题.由于TextViewImageView尺寸不明确.

在此输入图像描述

我不知道如何拆分Liner布局.我尝试像这样计算rootlayout高度

linearLayout.post(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                int linsize=linearLayout.getHeight();
                int relsize=root.getHeight();
                int textsize=txt1.getHeight();
                mainheight=relsize;
                subheight=linsize;
                Toast.makeText(getApplicationContext(), "Linerlayout "+linsize, Toast.LENGTH_LONG).show();
                Toast.makeText(getApplicationContext(), "Relative layout"+relsize, Toast.LENGTH_LONG).show();
                Toast.makeText(getApplicationContext(), "text height "+textsize, Toast.LENGTH_LONG).show();

                if(mainheight==subheight)
                {
                    Toast.makeText(getApplicationContext(), "make a new linear layout", Toast.LENGTH_LONG).show();
                    createsubview();
                }
            }
        }); 
Run Code Online (Sandbox Code Playgroud)

截图

在此输入图像描述

Mat*_*lor 6

您可以使用嵌套来轻松完成此操作LinearLayouts:

 <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/item" />

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

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >

            <ImageView
                content here/>

            <TextView
                content here/>

        </LinearLayout>
    </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

然后,您需要做的就是将A,B和C放在第一个垂直布局中,将D,E和F放在第二个布局中.