だから私はその周りにクールな境界線を持つTextViewが欲しかったのです。私はそれを行うための標準的な方法を見つけることができなかったので、私はこれを思いついた:
@ drawable / custom_bg_1:青い丸い形
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#439CC8"/>
<corners android:radius="3dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
@ drawable / custom_bg_2:白い丸みを帯びた形
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<corners android:radius="3dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
myactivity.xml:アクティビティのxml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15dp" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="2dp"
android:background="@drawable/custom_bg_1" >
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/curr_loc"
android:textSize="15sp"
android:background="@drawable/custom_bg_2" />
</LinearLayout>
</Linearlayout>
結果:
ここで行っているのは、青い図形の背景の内側に白い図形の背景を重ねて、青い境界線の効果を与えることです。これがこの効果を得る最良の方法だとは想像できません。thisやthisなど、この問題を解決しようとする他の投稿を見たことがありますが、それらは私の実装と同じくらい多くの回避策であると感じています。
TextViewなどの特定のビューの周囲に境界線を配置するより良い方法またはより標準的な方法はありますか、それとも私が行っている方法に固執する必要がありますか?
編集
custom_bg_2.xmlを次のように変更しました。
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="2dp" android:color="#000000"/>
<corners android:radius="3dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
そして今、私はこの結果を得ます:
形に入れることで輪郭が出せるよう<stroke ... />
です。