0

在此处输入图像描述

我的代码:

<LinearLayout
       android:layout_width="match_parent"
       android:layout_height="30dp"
       android:background="@drawable/myCustomShapeDrawable"
       android:orientation="horizontal" >

            <View 
                android:layout_height="match_parent"
                android:layout_width="0.4px"
                android:layout_gravity="center"
                android:background="#cccccc"/>
</LinearLayout>

如您所见,第一个问题是线的高度与 LinearLayout 的高度不匹配,尽管其高度属性中有“match_parent”。第二个问题是它没有在 LinearLayout 的中心对齐。

4

1 回答 1

0

下面的代码将根据要求工作:

 <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="30dp"
           android:layout_gravity="center"
           android:gravity="center"
           android:background="@drawable/myCustomShapeDrawable"
           android:orientation="horizontal" >

                <View 
                    android:layout_height="match_parent"
                    android:layout_width="0.4px"
                    android:layout_gravity="center"
                    android:background="#cccccc"/>
    </LinearLayout>
于 2016-08-29T12:36:49.707 回答