0

首先,我创建了从 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>
4

2 回答 2

0

更改 com.sample.viewGroup.CustomViewGroup

com.sample.viewGroup.CustomGroupView

于 2013-11-12T16:15:48.570 回答
0

我添加了这个,它有效。

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

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

}
于 2013-11-13T16:03:59.527 回答