XML ファイル (box.xml) からレイアウトを取得するカスタム コンポーネントを作成しようとしています。いくつかのチュートリアルを実行しましたが、何も表示できないようです。以下はカスタム コンポーネントのコンストラクタで、コードはエラーなしで実行されます。
public class MyView extends LinearLayout {
//Constructor required for inflation from resource file
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=layoutInflater.inflate (R.layout.box, this);
Log.d("CONSTRUCTOR 2", "TESTER");
}
}
これを使用して、コンポーネントをレイアウトに追加します。
<com.mysample.MyView android:layout_width="50dp" android:layout_height="38dp" android:background="#FF000000" />
黒いブロックは画面に表示されますが、膨張させたxmlファイルのレイアウトでは表示されません。