How to draw a border at top of the linear layout
I have followed the example in for the gradient dividers: http://www.connorgarvey.com/blog/?开发者_如何学Gop=34
I have tried to draw a horizontal line at the BOTTOM of my linear layout.
Here is my linear layout file:
<LinearLayout android:id="@+id/test" android:layout_width="fill_parent"
android:layout_height="wrap_content>
<ImageView android:id="@+id/icon1"
android:layout_width="32dip"
android:layout_height="32dip"
/>
And I did add
<View
android:background="@drawable/black_white_gradient"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_above="@id/test"
/>
But i don't see any line at the top of the LinearLayout. And when I go to Hierarchy View and see he View (for the hort separator), the getWidth() is 0 while getHeight() is 1.
Can you please tell me what am I missing?
Thank you.
With the code you posted ,its perfectly fine.But the fact that the size is 1dp
may not be showing it . increase the size or as you want only a line use this default line drawable from android
android:background="@android:drawable/divider_horizontal_bright"
// this for white background only
I hope this will help you get what you want
I think the orientation might be missing in the parent linearlayout view;
<LinearLayout android:orientation="vertical"
Or if you use RelativeLayout instead of LinearLayout, you can set 's layout_alignParentBottom;
<View android:layout_alignParentBottom="true"
It will not be visible if the height is 1dp. Try 2dp instead:
<View
android:background="@drawable/black_white_gradient"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_above="@id/test"
/>
The black border is only shown if the size is at least 2dp. Try removing the border, and set the solid color to black:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#000" />
</shape>
Than you can use a height of 1dp again.
精彩评论