因此,如果我有 aLinearLayout并在其中有几个孩子Views,比如一对ButtonsaTextView和 a CheckBox,使用LinearLayout'sgetChildAt(x)我会得到一个未指定的View. 需要注意的是,我没有在其中使用 xml,所以这一切都是以编程方式完成的。
public class CustomViewClass extends LinearLayout {
private Context context;
public CustomViewClass (Context context) {
super(context);
this.context = context;
setOrientation(LinearLayout.VERTICAL);
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
setBackgroundColor(Color.DKGRAY);
// Code which adds Buttons and such to the LinearLayout
getChildAt(1)
}
}
,getChildAt(1)无论如何我可以找出View它是什么类型的,无论是 aButton还是 aTextView或其他任何程序?