林试图创建这样的东西(颜色只是为了更好地理解,背景将是白色的):
我的问题是3个框包含两个TextView,一个在另一个下。
到目前为止,这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<!-- row 1 -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView0"
android:textSize="24dp"
android:padding="16dp"
android:background="#3366ff"/>
<!-- row 1 end -->
<!-- row 2 -->
<!-- col 1 -->
<TextView
android:padding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView1"
android:background="#aaaaaa"
/>
<TextView
android:padding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView1A"
android:background="#cccccc"
/>
<!-- col 1 end -->
<!-- col 2 -->
<TextView
android:padding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView2"
android:background="#bbbbbb"
/>
<TextView
android:padding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView2A"
android:background="#dddddd"
/>
<!-- col 2 end -->
<!-- col 3 -->
<TextView
android:padding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView3"
android:background="#cccccc"
/>
<TextView
android:padding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView3A"
android:background="#eeeeee"
/>
<!-- col 3 end -->
<!-- row 2 end -->
</LinearLayout>
这是我的代码不完整的结果:
我正在尝试LinearLayout
和RelativeLayout
。我完全不了解最后一个。
您可以尝试如下操作:
将每列的两个textview放在LinearLayout(垂直)下,最后将三个LinearLayouts放在水平LinearLayout下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- row 1 -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#3366ff"
android:padding="16dp"
android:text="TextView0"
android:textSize="24dp" />
<!-- row 1 end -->
<!-- row 2 -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3" >
<!-- col 1 -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#aaaaaa"
android:padding="8dp"
android:text="TextView1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#cccccc"
android:padding="8dp"
android:text="TextView1A" />
</LinearLayout>
<!-- col 1 end -->
<!-- col 2 -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#bbbbbb"
android:padding="8dp"
android:text="TextView2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#dddddd"
android:padding="8dp"
android:text="TextView2A" />
</LinearLayout>
<!-- col 2 end -->
<!-- col 3 -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#cccccc"
android:padding="8dp"
android:text="TextView3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#eeeeee"
android:padding="8dp"
android:text="TextView3A" />
</LinearLayout>
</LinearLayout>
<!-- col 3 end -->
</LinearLayout>
将重量用于所有三列线性布局的均等权重。
屏幕截图:
希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句