xmlレイアウトをカスタムViewGroup
に拡張しようとしています。レイアウトを拡張した後、ViewGroup
は、レイアウトのルートビューのみを表示します。実際には、完全レイアウトファイルをViewGroup
に表示する必要があります。カスタムViewGroupへのXMLレイアウトの膨張
私はstackoverflowや他のウェブサイトでこれに関連して掲載されている他の同様の質問を行っているが、役に立たなかった。ここで
は私のカスタムViewGroup
のコードです:レイアウトファイル
ViewEvent event = new ViewEvent(getApplicationContext());
LayoutInflater inflator;
inflator=(LayoutInflater)appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflator.inflate(R.layout.try1, event);
setContentView(event);
以下の通りである:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffaa77">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffff0000"
android:text="asdasadfas" />
</LinearLayout>
を
Activity
で
public class ViewEvent extends ViewGroup {
private final String LOG_TAG="Month View Event";
public ViewEvent(Context context) {
super(context);
}
public ViewEvent(Context context,AttributeSet attrs) {
super(context,attrs);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int childCount= getChildCount();
for(int i=0;i<childCount;i++)
{
Log.i(LOG_TAG, "Child: " + i + ", Layout [l,r,t,b]: " + l + "," + r + "," + t + "," + b);
View v=getChildAt(i);
if(v instanceof LinearLayout)
{
Log.i(LOG_TAG, "Event child count: " + ((ViewGroup)v).getChildCount()); // displaying the child count 1
v.layout(0, 0, r-l, b-t);
}
//v.layout(l, r, t, b);
}
}
、私はこのカスタムビューグループを使用しています
このレイアウトを拡張した後、私はルートを取得していますLinearLayout
のバックグラウンドカラーは#ffff0000
です。 TextView
は表示されません。
どこが間違っているのか、見つからないのですか?
それはアクセス可能ですが、それは表示されません! –