Xin chào mọi người hôm nay mình sẽ giới thiệu cho các bạn về Custom shape LinearLayout với những kiểu bolder khác nhau, trong bài này mình sẽ custom linearLayout theo hình chữ nhật.

Trước tiên bạn hãy tạo một file shape_linerlayout.xml trong drawable.


<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle" >
    <item>        <shape>            <!-- set the shadow color here -->            <stroke                android:width="2dp"                android:color="#7000" />
            <!-- setting the thickness of shadow (positive value will give shadow on that side) -->
            <padding                android:bottom="2dp"                android:left="2dp"                android:right="-1dp"                android:top="-1dp" />
            <corners android:radius="10dp" />        </shape>    </item>
    <item>        <shape>            <solid android:color="#fff" />            <corners android:radius="10dp" />        </shape>    </item></layer-list>
Tạo một layout acitivty_layout.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#866122"    android:orientation="vertical"    >    <RelativeLayout        android:layout_width="match_parent"        android:padding="10dp"        android:background="#9A970E"        android:layout_height="wrap_content">        <ImageView            android:layout_width="wrap_content"            android:layout_centerVertical="true"            android:src="@drawable/ic_home_black_24dp"            android:padding="10dp"            android:contentDescription="@string/app_name"            android:layout_height="wrap_content" />        <TextView            android:layout_width="wrap_content"            android:layout_centerHorizontal="true"            android:text="@string/app_name"            android:textSize="30sp"            android:textColor="#fff"            android:textStyle="bold"            android:layout_height="wrap_content" />        <ImageView            android:layout_width="wrap_content"            android:layout_alignParentRight="true"            android:layout_alignParentEnd="true"            android:layout_centerVertical="true"            android:contentDescription="@string/app_name"            android:padding="10dp"            android:src="@drawable/ic_settings_black_24dp"            android:layout_height="wrap_content" />    </RelativeLayout>    <ScrollView        android:layout_width="match_parent"        android:padding="5dp"        android:layout_height="wrap_content">        <LinearLayout            android:layout_width="match_parent"            android:orientation="vertical"            android:layout_height="wrap_content">            <LinearLayout                android:layout_width="match_parent"                android:background="@drawable/shape_linerlayout"                android:layout_margin="5dp"                android:orientation="vertical"                android:layout_height="wrap_content">                <TextView                    android:layout_width="match_parent"                    android:gravity="center"                    android:text="@string/txt_ip"                    android:padding="5dp"                    android:textSize="30sp"                    android:textColor="#000"                    android:layout_height="wrap_content" />                <TextView                    android:id="@+id/tv_ip"                    android:layout_width="match_parent"                    android:gravity="center"                    android:text="@string/txt_adress"                    android:padding="5dp"                    android:textSize="26sp"                    android:layout_height="wrap_content" />            </LinearLayout>            <LinearLayout                android:layout_width="match_parent"                android:layout_margin="5dp"                android:background="@drawable/shape_linerlayout"                android:orientation="vertical"                android:layout_height="wrap_content">                <TextView                    android:layout_width="match_parent"                    android:gravity="center"                    android:text="@string/txt_dns_1"                    android:padding="5dp"                    android:textSize="30sp"                    android:textColor="#000"                    android:layout_height="wrap_content" />                <TextView                    android:id="@+id/tv_dns1"                    android:layout_width="match_parent"                    android:gravity="center"                    android:text="@string/txt_adress"                    android:padding="5dp"                    android:textSize="26sp"                    android:layout_height="wrap_content" />            </LinearLayout>            <LinearLayout                android:layout_width="match_parent"                android:background="@drawable/shape_linerlayout"                android:layout_margin="5dp"
                android:orientation="vertical"                android:layout_height="wrap_content">                <TextView                    android:layout_width="match_parent"                    android:gravity="center"                    android:text="@string/txt_dns_2"                    android:textColor="#000"                    android:padding="5dp"                    android:textSize="30sp"                    android:layout_height="wrap_content" />                <TextView                    android:id="@+id/tv_dns2"                    android:layout_width="match_parent"                    android:gravity="center"                    android:text="@string/txt_adress"                    android:padding="5dp"                    android:textSize="26sp"                    android:layout_height="wrap_content" />            </LinearLayout>            <LinearLayout                android:layout_width="match_parent"                android:background="@drawable/shape_linerlayout"                android:layout_margin="5dp"
                android:orientation="vertical"                android:layout_height="wrap_content">                <TextView                    android:layout_width="match_parent"                    android:gravity="center"                    android:text="@string/txt_Geteway"                    android:textColor="#000"                    android:padding="5dp"                    android:textSize="30sp"                    android:layout_height="wrap_content" />                <TextView                    android:id="@+id/tv_geteway"                    android:layout_width="match_parent"                    android:gravity="center"                    android:text="@string/txt_adress"                    android:padding="5dp"                    android:textSize="26sp"                    android:layout_height="wrap_content" />            </LinearLayout>        </LinearLayout>    </ScrollView></LinearLayout>

Facebook Google twitter
Từ khóa: Custom shape LinearLayout Android