나는 추상 클래스 ViewGroup을 확장하여 사용자 정의 레이아웃 Android 구성 요소를 만듭니다 (Parleys.com의 Romain Guy가 제공 한 비디오 자습서 : http://www.parleys.com/#st=5&id=2191&sl=1).강제 사용자 정의 ViewGroup 하위 유형 및 개수
내 구성 요소에는 하위가 있어야하지만 하위 그룹은 ViewGroup 유형 (예 : 다른 LinearLayout 또는 RelativeLayout)으로 제한됩니다. Kindof는 ScrollView와 같습니다. 제한을 추가 할 수있는 방법이 있습니까?
편집 : 당신이 할 수있는
@Override
public void onFinishInflate()
{
if (getChildCount() > 1)
throw new IllegalArgumentException("Only 1 child allowed");
if (getChildCount() == 0 || !(getChildAt(0) instanceof ViewGroup))
throw new IllegalArgumentException("Child must be a ViewGroup");
}
는 의미 적, 내가'IllegalStateException'이 IllegalArgumentException''보다 더 적합 할 것이라고 생각 사용할 수 있습니다. 그러나 쉬운 웹 검색을위한 감사. –
또한 View 클래스의 문서에는 현재 아무것도 수행하지 않더라도 수퍼 클래스 구현 ('super.onFinishInflate()') 호출을 요구하는 정책이 포함되어 있습니다 (http : /developer.android.com/reference/android/view/View.html#onFinishInflate%28%29 –