gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:44:35 24 4
gpt4 key购买 nike

我必须将单个线性布局拆分为两列(像报纸栏)。线性布局包含text-viewimage-view

我已经采用屏幕宽度并将其分成两半,并使 TextViewImageView 位于第一列,即 A B C block 在下图中.. 现在剩下的 TextView 和 'ImageView 必须像 D E F 那样转到下一列on.So 如果有人给我任何代码或想法来实现这个,那将会很有帮助。我尝试使用 GridView 但这不适合我的问题。 因为 TextViewImageView 大小不确定。

enter image description here

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

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

截图

enter image description here

最佳答案

您可以使用嵌套的 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 放在第二个中。

关于android - 如何将线性布局拆分为两列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15269517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com