XML ファイルからグループを拡張した後、複合ビューグループを作成しようとしています。
ビューグループは次のように構成されています: LinearLayout ルート、2 つの子 LinearLayouts。レイアウト エディターでレイアウトを正しく表示できます。ただし、エディターからビュー (ボタンなど) を追加しようとすると、ビューが表示されず、アプリケーションがすぐに強制終了します。ビュー コンポーネントを正しく描画するには、onLayout メソッドをオーバーライドする必要があるかもしれないと言われましたが、かなり混乱しています。
私のクラス:
public class FocusBox extends LinearLayout {
private LinearLayout rootLayout,
contentLayout,
topLayout;
public FocusBox(Context context)
{
super(context, null);
}
public FocusBox(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.focus_box, this);
rootLayout = (LinearLayout)findViewById(R.id.focusBoxParent);
contentLayout = (LinearLayout)findViewById(R.id.focusBottom);
topLayout = (LinearLayout)findViewById(R.id.focusTop);
}
}
そしてxml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp"
android:id="@+id/focusBoxParent"
android:orientation="vertical">
<LinearLayout
android:background="@drawable/gradients"
android:layout_weight=".1"
android:gravity="center"
android:id="@+id/focusTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="TextView"
android:id="@+id/focusTitle"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_width="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight=".9"
android:id="@+id/focusBottom"
android:background="@drawable/gradient2"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>