拡張するクラスがありますLinearLayout
コンストラクターで私が呼び出す
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout view = (LinearLayout)inflater.inflate(R.layout.titlebar, this, true);
このビューでビューにアクセスできますが、描画されません。その理由は、このビューの mParent がまだ null であるためだと思います。しかし、なぜ?Partent はこれでなければなりません (LinearLayout を拡張するクラス)
ここでxml:
<RelativeLayout android:id="@+id/header"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="35px"
android:layout_width="fill_parent"
android:background="@drawable/titlebar_bg">
<TextView android:layout_width="wrap_content"
android:textColor="#000000"
android:text="test"
android:id="@+id/title"
android:layout_alignParentTop="true"
android:layout_marginLeft="10pt"
android:layout_height="wrap_content"
android:textSize="10pt"
android:layout_marginTop="3dip"></TextView>
<TextView android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="10:09 AM"
android:id="@+id/time"
android:textColor="#000000"
android:layout_alignParentRight="true"
android:layout_marginRight="5px"
android:layout_marginTop="3px"
android:textSize="10pt"></TextView></RelativeLayout>
解決
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:layout_width="wrap_content"
android:textColor="#000000"
android:text="test"
android:id="@+id/title"
android:layout_alignParentTop="true"
android:layout_marginLeft="10pt"
android:layout_height="wrap_content"
android:textSize="10pt"
android:layout_marginTop="3dip"></TextView>
<TextView android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="10:09 AM"
android:id="@+id/time"
android:textColor="#000000"
android:layout_alignParentRight="true"
android:layout_marginRight="5px"
android:layout_marginTop="3px"
android:textSize="10pt"></TextView>
merge タグを使用し、xml タグを使用します。
<package.Titlebar
android:id="@+id/testtitlebar"
android:layout_height="35px"
android:layout_width="fill_parent"
android:background="@drawable/titlebar_bg"></package.Titlebar>
これはクラスでどのように見えるかです:
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.titlebar, this);
onLayout関数はありません!!! 私の欠点の一つ