AndroidでカスタムViewを作りたくて、ネットで勉強していますが、なかなかわからないことがあります。
Layoutを継承したカスタムViewの上の部品を、xmlで指定しているのは見るんですが、
Viewを継承したカスタムViewでは、xmlで指定しているようなものは見ません。
onDrawで見た目を指定しているものは見るんですが、xmlでしていできないでしょうか?
それとも、onDrawで見た目を描画したものを表示することしかできないんでしょうか?
自分が作りたいカスタムViewは、Buttonの上にTextViewが複数個載っている様なものです。
下に、実際に指定したい配置のxmlの例を載せます。
xml
1<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:orientation="vertical" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:background="#ffffaaaa"> 6 <LinearLayout 7 android:layout_width="wrap_content" 8 android:layout_height="wrap_content" 9 android:orientation="horizontal"> 10 <ImageView 11 android:layout_width="5dp" 12 android:layout_height="5dp" 13 android:background="#ffff0000" 14 15 /> 16 <TextView 17 android:layout_width="match_parent" 18 android:layout_height="match_parent" 19 android:text="Title" 20 android:id="@+id/title"/> 21 </LinearLayout> 22 <TextView 23 android:layout_width="wrap_content" 24 android:layout_height="wrap_content" 25 android:text="MainText" 26 android:layout_gravity="center" 27 android:id="@+id/mainText" 28 /> 29 <TextView 30 android:layout_width="wrap_content" 31 android:layout_height="wrap_content" 32 android:layout_gravity="bottom|end" 33 android:text="Date" 34 android:id="@+id/date"/> 35</LinearLayout>
(追記)
Java
1public class Custom extends ViewGroup { 2 public Custom(Context context, AttributeSet attrs) { 3 super(context, attrs); 4 inflate(context,R.layout.custum,this); 5 } 6} 7
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。