I have followed the example in for the gradient dividers: http://www.connorgarvey.com/blog/?p=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.
To insert a simple border graphic around the whole layout (page), use the Insert > Graphics and Text option, selecting Rectangle. Once you've drawn it, you can change the properties to make it hollow (No Fill) and the outline to suit your border requirements.
You will have to expand one of your upper views to fill the remaining space by setting android:layout_weight="1" on it. This will push your last view down to the bottom.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code we have taken one text view with background as border so we need to create a file in drawable as boarder.
To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With