Thursday, 15 September 2011

android - Hard coding a rectangle with a border -



android - Hard coding a rectangle with a border -

i draw gray rectangle has reddish border around using xml i've seen beingness done in many different ways , i'd tell me way best in order accomplish this? below code want know if there easier way. no java please. want xml.

<relativelayout android:layout_width="10dp" android:layout_height="10dp" android:background="@color/red" android:layout_weight=".25"> <relativelayout android:layout_width="7dp" android:layout_height="7dp" android:background="@color/grey" android:layout_centerhorizontal="true" android:layout_centervertical="true"/> </relativelayout>

layout not aligning

<relativelayout android:layout_width="0dp" android:layout_height="40dp" android:background="@color/grey" android:layout_weight=".25" > <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:text="3" android:textcolor="@color/black"/> <relativelayout android:layout_width="10dp" android:layout_height="10dp" android:background="@color/red" android:layout_weight=".25"> <relativelayout android:layout_width="7dp" android:layout_height="7dp" android:background="@color/grey" android:layout_centerhorizontal="true" android:layout_centervertical="true"/> </relativelayout> <relativelayout android:layout_width="15dp" android:layout_height="10dp" android:background="@color/red" android:layout_alignparentleft="true"> <relativelayout android:layout_width="12dp" android:layout_height="7dp" android:background="@color/grey" android:layout_centerhorizontal="true" android:layout_centervertical="true"/> </relativelayout> <relativelayout android:layout_width="15dp" android:layout_height="10dp" android:background="@color/red" android:layout_alignparentright="true"> <relativelayout android:layout_width="12dp" android:layout_height="7dp" android:background="@color/grey" android:layout_centerhorizontal="true" android:layout_centervertical="true"/> </relativelayout> <relativelayout android:layout_width="15dp" android:layout_height="10dp" android:background="@color/red" android:layout_alignparentbottom="true" android:layout_alignparentleft="true"> <relativelayout android:layout_width="12dp" android:layout_height="7dp" android:background="@color/grey" android:layout_centerhorizontal="true" android:layout_centervertical="true"/> </relativelayout> <relativelayout android:layout_width="15dp" android:layout_height="10dp" android:background="@color/red" android:layout_alignparentbottom="true" android:layout_centerhorizontal="true" android:padding="1.5dp"> <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/grey" android:layout_centerhorizontal="true" android:layout_centervertical="true"/> </relativelayout> <relativelayout android:layout_width="15dp" android:layout_height="10dp" android:background="@color/red" android:layout_alignparentbottom="true" android:layout_alignparentright="true"> <relativelayout android:layout_width="12dp" android:layout_height="7dp" android:background="@color/grey" android:layout_centerhorizontal="true" android:layout_centervertical="true"/> </relativelayout> </relativelayout>

in drawable rectangle.xml

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="#d7d5d6" > </solid> <stroke android:width="0.5dp" android:color="#ff0000" > </stroke> </shape>

and layout.

<?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:orientation="vertical" android:background="@drawable/rectangle" > </linearlayout>

you can alter desired color code , width of border.

android xml android-layout android-activity

No comments:

Post a Comment