xml レイアウトを custom に膨らませようとしていますViewGroup
。レイアウトをインフレートした後、レイアウトViewGroup
のルート ビューのみを表示します。実際には、完全なレイアウト ファイルを .xml ファイルに表示する必要がありますViewGroup
。
これに関連してstackoverflowや他のWebサイトに投稿された他の同様の質問を調べましたが、役に立ちませんでした。
これが私のカスタムのコードですViewGroup
:
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);
}
}
では、次のActivity
カスタム ビュー グループを使用しています。
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>
このレイアウトを膨らませた後LinearLayout
、背景色のルートのみを取得しています#ffff0000
。TextView
表示されません。
どこで間違っているか、何かが欠けていますか?