androidコーディングメモ
画面に横線を引く方法
横線を引くのが難しかったので記録を残すことにします。
(1)Layouot.xmlにTextViewを定義する
★layouot.xml
<TextView
android:id="@+id/textView_line"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
(2)res/drawableの下にline.xmlファイルを置く
★line.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="3sp" android:color="#CCCCCC" />
</shape>
(3)ActivityからTextViewに線をセットする
★Activity
//TextViewに線をセット
TextView textView = (TextView) findViewById(R.id.textView_line);
textView.setBackgroundResource(R.drawable.line);
ちなみに、
線をクリアする場合はこのようにする
// 線をクリア
textView.setBackgroundDrawable(null);
他に良い方法があったら教えてください
画面に横線を引く方法
横線を引くのが難しかったので記録を残すことにします。
(1)Layouot.xmlにTextViewを定義する
★layouot.xml
<TextView
android:id="@+id/textView_line"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
(2)res/drawableの下にline.xmlファイルを置く
★line.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="3sp" android:color="#CCCCCC" />
</shape>
(3)ActivityからTextViewに線をセットする
★Activity
//TextViewに線をセット
TextView textView = (TextView) findViewById(R.id.textView_line);
textView.setBackgroundResource(R.drawable.line);
ちなみに、
線をクリアする場合はこのようにする
// 線をクリア
textView.setBackgroundDrawable(null);
他に良い方法があったら教えてください