如何分割线布局两列?布局、分割线

2023-09-06 01:02:35 作者:傲气小仙女

我要拆分单一的线性布局成两列(像报纸专栏),线性布局包含的文本视图和图片视图

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

我已经采取了屏幕的宽度并划分到一半,并提出了的TextView 的ImageView 进来第一列,即农行在下面的图片..现在剩下的的TextView 和块 ImageView的已经去到下一列像 DEF 一样,它去on.So这将是有益的,如果有人给我任何code或想法来实现这个..我试着用的GridView 这是不适合我的问题。 由于的TextView 的ImageView 尺寸不明确的。的

I have taken the screen width and have divided it to half and made the TextView and ImageView to come in a first column , ie, A B C blocks in the picture below.. now the remaining TextView and 'ImageView has to go to next column like in D E F like that it goes on.So it would be helpful if anyone gives me any code or ideas to implement this.. I tried with GridView which is not suitable for my issue. Since the TextView and ImageView sizes are not definite.

我不知道如何分割班轮布局。 我试着用计算rootlayout高度 像这样

I don't know how to split Liner layout. I tried with calculating the rootlayout height like this

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();
                }
            }
        }); 

截图

推荐答案

您可以很容易地嵌套做到这一点 LinearLayouts

You could easily do this with nested 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>

然后,所有你需要做的就是把A,B和C在第一垂直布局,D,E和F在第二。

Then all that you need to do is put A, B and C in the first vertical layout, and D, E and F in the second.

 
精彩推荐
图片推荐