簡體   English   中英

兩列,一列分成兩行 - Android

[英]Two columns with one column split into two rows - Android

我正在嘗試實現一個有兩列的TableLayout ,第二列被分成兩行。 像這樣的東西:

在此處輸入圖片說明

到目前為止我所擁有的是這樣的東西,它基本上創建了三列:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TableRow
        android:id="@+id/tr1"
        android:layout_width="wrap_content"
        android:layout_height="160dp"
        >

        <ImageView
            android:src="@drawable/icon"
            android:layout_span="1"
            android:layout_height="160dp"
            android:layout_width="200dp"
            android:scaleType="centerCrop"
            />

        <ImageView
            android:src="@drawable/icon"
            android:layout_height="75dp"
            android:layout_width="wrap_content"
            android:scaleType="centerCrop"
            />

        <ImageView
            android:src="@drawable/icon"
            android:layout_height="75dp"
            android:scaleType="centerCrop"
            android:layout_width="wrap_content"/>

    </TableRow>

</TableLayout>

您可以通過組合LinearLayout而不是TableLayout來實現這一點:

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="144dp"
    android:layout_weight="0.5"
    android:background="@android:color/holo_red_dark">

    // Column A.
    // Put your content here..

</LinearLayout>

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="144dp"
    android:orientation="vertical"
    android:weightSum="1"
    android:layout_weight="0.5">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="72dp"
        android:background="@android:color/holo_green_dark"
        android:layout_weight="0.5">

        // Column B, row 1.
        // Put your content here..

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="72dp"
        android:background="@android:color/holo_blue_dark"
        android:layout_weight="0.5">

        // Column B, row 2.
        // Put your content here..

    </LinearLayout>

</LinearLayout>

這是它將產生的布局:

在此處輸入圖片說明

您可以使用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="100dp"
android:orientation="horizontal">

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

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

但是,您可以使用RelativeLayout以獲得更好的性能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM