利用布局叠加的方法来解决一个难搞的view布局问题

144 阅读1分钟

布局画面

要求是 先右侧自适应,然后中间自适应大小,最后让左边自适应大小不够显示...
问题的难点在于,在我们开发过程中设计此类问题时正常的布局方式总是挤压右侧的布局,无法使右侧布局自适应大小.
我们通过如下布局嵌套则可以做到此问题解决方案.
<RelativeLayout
        android:paddingLeft="@dimen/x8"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:id="@+id/topName"
            android:paddingLeft="@dimen/x18"
            android:layout_marginTop="@dimen/x16"
            android:layout_toLeftOf="@+id/check_box"
            android:layout_marginRight="@dimen/x21"
            android:gravity="center_vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <TextView
                    android:id="@+id/item_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    tools:text="课程节点名称课程节点名称课程节点名称课程节点名称"
                    android:singleLine="true"
                    android:ellipsize="end"
                    android:layout_weight="1"
                    android:textColor="@color/c_2b2d44"
                    android:textSize="@dimen/x16"
                    />
                <TextView
                    android:id="@+id/item_type"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/x8"
                    android:paddingTop="@dimen/x2"
                    android:paddingBottom="@dimen/x2"
                    android:paddingLeft="@dimen/x4"
                    tools:text="录播"
                    android:paddingRight="@dimen/x4"
                    android:background="@drawable/bg_corner_radius2_f1f1f1"
                    android:textColor="@color/c_6a6c7c"
                    android:textSize="@dimen/x10" />
            </LinearLayout>

        </LinearLayout>
        <ImageView
            android:id="@+id/check_box"
            android:src="@drawable/icon_download_check_nomal_weektask"
            android:layout_alignParentRight="true"
            android:layout_marginRight="@dimen/x18"
            android:layout_marginTop="@dimen/x21"
            android:layout_width="@dimen/x22"
            android:layout_height="@dimen/x22"/>
    </RelativeLayout>