右側の数字に下の画像のような背景を要求するデザインがあります。Android でこれを達成できるものはありますか?
9 パッチ画像を作成して背景として設定する必要がありますか?
まず、角が丸くなる形状を作成します。
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<corners android:radius="5px"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
次に、これを背景としてビューに適用します。
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_edges">
<TextView
android:id="@+id/mytext"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:text="blah blah blah blah"
android:padding="6dip"
android:textColor="#000000" />
</LinearLayout>
微調整が必要な場合があります。を破棄して、のをLinearLayout
に設定することもできる場合がありますandroid:background
TextView
@drawable/rounded_edges
まず、描画可能なリソースを作成します。
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_textview.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#cccccc"/>
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>
次に、レイアウトでこのドローアブルを参照します。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:gravity="center"
android:background="@drawable/rounded_textview" />
</LinearLayout>
良いリファレンスの1つ:
ありがとう。