Android 如何实现这种布局

Android 如何实现这种布局,android,android-layout,Android,Android Layout,这是最新的 我尝试使用LinearLayout实现它,如下所示: <LinearLayout android:clickable="true" android:focusable="true" android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="match_parent"

这是最新的

我尝试使用
LinearLayout
实现它,如下所示:

    <LinearLayout
        android:clickable="true"
        android:focusable="true"
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:gravity="center">

        <TextView
            android:text="Type"
            android:background="@drawable/poi_nearby_cell"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:layout_weight="1"/>

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

            <TextView
                android:text="Type1"
                android:background="@drawable/poi_nearby_cell"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"/>

            <TextView
                android:text="Type2"
                android:background="@drawable/poi_nearby_cell"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"/>
        </LinearLayout>

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

            <TextView
                android:text="Type3"
                android:background="@drawable/poi_nearby_cell"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"/>

            <TextView
                android:text="Type4"
                android:background="@drawable/poi_nearby_cell"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"/>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <color android:color="#ffebf6ff"/>
    </item>
    <item>
        <color android:color="#fffefefe"/>
    </item>
</selector>
这就是我现在得到的

但是我遇到了很多问题:

1我使用
drawable/poi_nearnear_单元格
为textview创建边框

然而,我还必须实现细胞压效果,就像设计效果图片中的“Type1”。通常我将axml drawable resource设置为如下背景:

    <LinearLayout
        android:clickable="true"
        android:focusable="true"
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:gravity="center">

        <TextView
            android:text="Type"
            android:background="@drawable/poi_nearby_cell"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:layout_weight="1"/>

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

            <TextView
                android:text="Type1"
                android:background="@drawable/poi_nearby_cell"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"/>

            <TextView
                android:text="Type2"
                android:background="@drawable/poi_nearby_cell"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"/>
        </LinearLayout>

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

            <TextView
                android:text="Type3"
                android:background="@drawable/poi_nearby_cell"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"/>

            <TextView
                android:text="Type4"
                android:background="@drawable/poi_nearby_cell"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"/>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <color android:color="#ffebf6ff"/>
    </item>
    <item>
        <color android:color="#fffefefe"/>
    </item>
</selector>

但是在我的例子中,我不能同时设置具有两个背景的视图。还有别的选择吗

2如您所见,边框的宽度值不同。通常我希望边框是
1dp
,但是在我的示例中,两个单元格之间的边框可能是
2dp

我不知道要继续下去。有什么建议吗?

//试试这个
// try this
**layout_bg.xml**
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="#333333" />

    <corners android:radius="5dp" />

    <stroke
        android:width="1dp"
        android:color="@android:color/darker_gray" />

</shape>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:clickable="true"
    android:focusable="true"
    android:orientation="horizontal"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:padding="5dp"
    android:gravity="center">

    <LinearLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:background="@drawable/layout_bg"
        android:padding="1dp">

        <LinearLayout
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:padding="1dp"
            android:background="@android:color/darker_gray"
            android:layout_weight="1">
            <LinearLayout
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:background="@android:color/white"
                android:orientation="vertical">
                <TextView
                    android:text="Type"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"/>
            </LinearLayout>
        </LinearLayout>


        <LinearLayout
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:orientation="vertical"
            android:layout_weight="1">
            <LinearLayout
                android:layout_height="0dp"
                android:layout_weight="1"
                android:padding="1dp"
                android:layout_width="match_parent"
                android:background="@android:color/darker_gray"
                android:orientation="vertical">
                <LinearLayout
                    android:layout_height="match_parent"
                    android:layout_width="match_parent"
                    android:gravity="center"
                    android:background="@android:color/white">

                    <TextView
                        android:text="Type1"
                        android:layout_height="wrap_content"
                        android:layout_width="match_parent"/>
                </LinearLayout>
            </LinearLayout>
            <LinearLayout
                android:layout_height="0dp"
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:background="@android:color/darker_gray"
                android:padding="1dp"
                android:orientation="vertical">
                <LinearLayout
                    android:layout_height="match_parent"
                    android:layout_width="match_parent"
                    android:gravity="center"
                    android:background="@android:color/white">
                    <TextView
                        android:text="Type2"
                        android:layout_height="wrap_content"
                        android:layout_width="match_parent"/>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:orientation="vertical"
            android:layout_weight="1">
            <LinearLayout
                android:layout_height="0dp"
                android:layout_weight="1"
                android:padding="1dp"
                android:layout_width="match_parent"
                android:background="@android:color/darker_gray"
                android:orientation="vertical">
                <LinearLayout
                    android:layout_height="match_parent"
                    android:layout_width="match_parent"
                    android:gravity="center"
                    android:background="@android:color/white">

                    <TextView
                        android:text="Type3"
                        android:layout_height="wrap_content"
                        android:layout_width="match_parent"/>
                </LinearLayout>
            </LinearLayout>
            <LinearLayout
                android:layout_height="0dp"
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:background="@android:color/darker_gray"
                android:padding="1dp"
                android:orientation="vertical">
                <LinearLayout
                    android:layout_height="match_parent"
                    android:layout_width="match_parent"
                    android:gravity="center"
                    android:background="@android:color/white">
                    <TextView
                        android:text="Type4"
                        android:layout_height="wrap_content"
                        android:layout_width="match_parent"/>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
**layout_bg.xml**
我尝试了表格布局,但它不支持行间距。请在表格中使用表格:带有2列和一行的外部表格。右面板内有2列3行。那么单元格边框和单元格按下方式如何?@hguser它支持@雷基尔:。看看这个。