创建视图填充包装内容父布局

时间:2015-04-08 19:17:53

标签: android android-layout view layoutparams

What it should look like Screenshot of the problem

我正在尝试为组织硬件的Android应用程序添加类的颜色编码。我试图通过在类的颜色上添加一个栏来做到这一点。在图像中,我希望整个布局包装文本的高度,然后使用Shape A填充该布局。我尝试在形状A上使用匹配父项,但这不起作用。之后,我尝试做的是以编程方式测量相对布局,并将形状A设置为始终有效的高度,除非文本必须换行到两行。所有帮助表示赞赏。谢谢!

XML代码:ID为side_bar的电视是我试图添加的边栏。

<?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">


<RelativeLayout
    android:id="@+id/rel_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF">


    <RelativeLayout
        android:id="@+id/check_layout"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerVertical="true">

        <change.com.puddl.CheckBox
            android:id="@+id/checkBox"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_centerVertical="true"
            android:background="#4CAF50" />

        <ImageView
            android:id="@+id/check"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:src="@drawable/ic_check_white_24dp"
            android:tint="#4CAF50"
            android:visibility="gone" />

    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/check_layout"
        android:background="#FFFFFF"
        android:orientation="vertical">

        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginTop="4dp"
            android:text="This is a summary..."
            android:textColor="#727272"
            android:textSize="20dp" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginTop="8dp">

            <TextView
                android:id="@+id/Due"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:text="Due"
                android:textColor="#888"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/Course"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:text="Course"
                android:textSize="12sp" />

        </RelativeLayout>


    </LinearLayout>

    <TextView
        android:id="@+id/side_bar"
        android:layout_width="4dp"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:background="#727272" />

</RelativeLayout>

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#DDDDDD" />

<View
    android:id="@+id/topShadow"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#DDDDDD"
    android:visibility="gone" />
</LinearLayout>

1 个答案:

答案 0 :(得分:1)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/row_base"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="@color/black">

    <!--your shape-->
    <LinearLayout
        android:layout_width="15dp"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/redDark">
    </LinearLayout>

    <!--check icon-->
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/gray_light1">

        <ImageView
            android:id="@+id/check"
            android:layout_gravity="center_vertical"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:src="@drawable/checked"
            android:tint="#4CAF50"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />
    </LinearLayout>

    <!--COntent, texts-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/gray_light3">

        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:text="This is a summary..."
            android:textColor="@color/black"
            android:textSize="20dp" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/gray_light2">

                    <TextView
                        android:id="@+id/Due"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_alignParentLeft="true"
                        android:text="Due"
                        android:textColor="@color/black"
                        android:textSize="12sp" />

                    <TextView
                        android:id="@+id/Course"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_alignParentRight="true"
                        android:text="Course"
                        android:textColor="@color/black"
                        android:textSize="12sp" />

        </RelativeLayout>


    </LinearLayout>

</LinearLayout>

enter image description here

当您将其用作列表项时,它将具有良好的视野。

相关问题