We can set the background color in the LinearLayout, but can't find the attribute about a border.
Now Let's see the following about setting borders around the LinearLayout.
The First way is to use Shape Object.
==== header_border.xml ====
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<padding android:left="10sp" android:right="10sp" android:top="10sp" android:bottom="10sp"/>
<solid android:color="@android:color/transparent"/>
<stroke
android:width="1sp"
android:color="#000000" />
</shape>
: Define header_border.xml like this. Then Save it into '/res/drawable-mdpi'
==== activie_main.xml ====
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="ffffff"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/header_border"
>
<ImageButton
android:id="@+id/side_menu"
android:layout_width="40sp"
android:layout_height="40sp"
android:background="@drawable/icon_list"
android:contentDescription="사이드 메뉴"
android:layout_marginTop="5sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="아이템 목록"
android:textSize="20sp"
android:layout_marginTop="5sp"
android:layout_weight="1"
android:gravity="center"
/>
<ImageButton
android:id="@+id/user_config"
android:layout_width="37sp"
android:layout_height="37sp"
android:background="@drawable/icon_config"
android:contentDescription="사용자 설정"
android:layout_marginTop="5sp"
android:layout_marginRight="5sp"
/>
</LinearLayout>
: Set the reference of header_border object as a background attribute's value. then We can find borders around the LinearLayout.
But I'd like to do that only the LinearLayout appears only bottom border.
We can see the following for it.
==== activity_main.xml ====
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="ffffff"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="f0fff0"
android:padding="10sp"
>
<ImageButton
android:id="@+id/side_menu"
android:layout_width="40sp"
android:layout_height="40sp"
android:background="@drawable/icon_list"
android:contentDescription="사이드 메뉴"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="아이템 목록"
android:textSize="20sp"
android:layout_marginTop="5sp"
android:layout_weight="1"
android:gravity="center"
/>
<ImageButton
android:id="@+id/user_config"
android:layout_width="37sp"
android:layout_height="37sp"
android:background="@drawable/icon_config"
android:contentDescription="사용자 설정"
/>
</LinearLayout>
<!-- This is LinearLayout for bottom border. -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="000000"
>
</LinearLayout>
</LinearLayout>
: We add a LinearLayout for bottom border. It has no child view. It just has layout_height "2dp" and background "000000" as values of the attributes.
We can see the bottom border like this.
'Android > Layout' 카테고리의 다른 글
Filling an Listview with data (0) | 2014.02.17 |
---|