Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a border at top of the linear layout

Tags:

android

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.

like image 347
n179911 Avatar asked Dec 17 '09 17:12

n179911


People also ask

How do I add a border to a layout?

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.

How do you set a view at the bottom of a linear layout?

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.

How do you add a border on android?

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.

How do you do a horizontal linear layout?

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


2 Answers

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

like image 74
1HaKr Avatar answered Oct 30 '22 01:10

1HaKr


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"
like image 20
hwii77 Avatar answered Oct 29 '22 23:10

hwii77