所以,如果我有一個LinearLayout
並有好幾個孩子Views
它裏面,說像情侶的Buttons
一個TextView
和CheckBox
,使用LinearLayout
的getChildAt(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
,無論它是一個Button
或TextView
或任何progamatically?