ShapeDrawable and LinearLayout not working as expected

105 Views Asked by At

enter image description here

My code:

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

As you can see, the first problem is that the line's height is not matching the LinearLayout's height, despite having "match_parent" at its height attribute. The second problem is that it doesnt align itself in the center of the LinearLayout.

1

There are 1 best solutions below

0
Avinash Mishra On

This below code will work according to the requirement:

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