Issue
There is such a picture As in the game 4 photos 1 word
I need to draw cells for letters. I do not remember the name of the style, it seems to me that Inner
, when the cell is concave inward.
And the fact is that I did not work with Photoshop
for drawing and use it with 9-Patch
. In the vast Internet did not find (or not properly searched).
So the question is how to draw such a button or cell in Drawable
?
Solution
1. Create a custom drawable
file bg_rounded_corners.xml
for rounded
black box
shape and put this drawable
into your res/drawable
folder.
bg_rounded_corners.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Bottom Shadow -->
<item>
<shape android:shape="rectangle" >
<solid android:color="#2F2F3D" />
<corners android:radius="4dp" />
</shape>
</item>
<!-- Top Shadow -->
<item android:bottom="2dp">
<shape android:shape="rectangle" >
<solid android:color="#000000" />
<corners android:radius="4dp" />
</shape>
</item>
<!-- Center Filled Color -->
<item
android:top="1dp"
android:bottom="1.5dp">
<shape android:shape="rectangle" >
<gradient
android:startColor="#160A0F"
android:centerColor="#190B0F"
android:endColor="#1B0C13"
android:angle="270"/>
<corners android:radius="4dp" />
</shape>
</item>
</layer-list>
2. Design your layout XML using LinearLayout
with Horizontal
orientation and put desired number of TextView
inside this LinearLayout
. Set custom drawable
to each TextView
using attribute android:background="@drawable/bg_rounded_corners"
.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:background="#202531">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="32dp"
android:layout_height="32dp"
android:gravity="center"
android:paddingBottom="2dp"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="@android:color/white"
android:text="H"
android:background="@drawable/bg_rounded_corners"/>
<TextView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="2dp"
android:paddingBottom="2dp"
android:gravity="center"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="@android:color/white"
android:text="E"
android:background="@drawable/bg_rounded_corners"/>
<TextView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="2dp"
android:paddingBottom="2dp"
android:gravity="center"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="@android:color/white"
android:text="L"
android:background="@drawable/bg_rounded_corners"/>
<TextView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="2dp"
android:paddingBottom="2dp"
android:gravity="center"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="@android:color/white"
android:text="L"
android:background="@drawable/bg_rounded_corners"/>
<TextView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="2dp"
android:paddingBottom="2dp"
android:gravity="center"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="@android:color/white"
android:text="O"
android:background="@drawable/bg_rounded_corners"/>
</LinearLayout>
</LinearLayout>
OUTPUT:
FYI, I have used color #202531
as background
color. For your case, you can use another color
or use any image
as background of root LinearLayout
.
Hope this will help~
Answered By - Ferdous Ahamed
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.