20

右側の数字に下の画像のような背景を要求するデザインがあります。Android でこれを達成できるものはありますか?

ここに画像の説明を入力

9 パッチ画像を作成して背景として設定する必要がありますか?

4

3 に答える 3

37

まず、角が丸くなる形状を作成します。

<?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:backgroundTextView@drawable/rounded_edges

于 2013-01-13T11:46:32.127 に答える
4

まず、描画可能なリソースを作成します。

<?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つ:

角が丸いTextView

ありがとう。

于 2013-01-13T11:49:15.710 に答える