自定义视图组中的预定义自定义视图不会显示在屏幕上

时间:2013-11-12 16:11:07

标签: android

首先,我创建了从View扩展的自定义视图。现在我想创建具有预定义子组的组视图。我尝试使用此代码,但我的观点没有显示:

public class CustomGroupView extends ViewGroup {

    public CustomGroupView(Context context, AttributeSet attrs) {
        super(context, attrs);

        addView(new CustomView(context, attrs));
    }


    @Override
    protected void onLayout(boolean hasFocus, int i, int i2, int i3, int i4) {

    }
}




<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">


    <com.sample.viewGroup.CustomGroupView
        android:layout_width="match_parent"
        android:layout_height="match_parent" />



</LinearLayout>

2 个答案:

答案 0 :(得分:0)

更改com.sample.viewGroup.CustomViewGroup

com.sample.viewGroup.CustomGroupView

答案 1 :(得分:0)

我添加了这个,它有效。

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {

  child.layout(right, top, left, bottom);

}
相关问题