Web タブに似たウィジェットを作成する必要があるため、線形の laoyut とボタンを含む単純な tabs.xml を作成しましたが、そのビューに挿入する追加のロジックが必要なので、単純にアクティビティに tabs.xml を含めるだけでは十分ではありません (試していますそこに属していないため、すべてのコードをアクティビティにプッシュすることを避けるため)。LinearLayout クラスを拡張して作成したビューで infalte tabs.xml を使用するにはどうすればよいですか?
1 に答える
2
作成した .xml レイアウトをインフレートする必要があります。
次のようにします。
public class CustomLinearLayout extends LinearLayout {
// you need this constructor when you use the customview from code
public CustomLinearLayout (Context context) {
super(context);
addView(LayoutInflater.from(context).inflate(R.layout.yourlayout, null));
}
// you need this constructor when the customview is used from .xml
public CustomLinearLayout (Context context, AttributeSet attrs) {
super(context, attrs);
addView(LayoutInflater.from(context).inflate(R.layout.yourlayout, null));
}
}
于 2013-09-08T17:05:00.747 に答える