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