-1
我想在this.getLayoutParams()
上避免ClassCastException
。有沒有一種方法可以獲得佈局類型,即相對,線性或框架? 然後我想在結果上使用開關盒,然後做this.getLayoutParams()
。如何找到視圖的佈局類型?
我想在this.getLayoutParams()
上避免ClassCastException
。有沒有一種方法可以獲得佈局類型,即相對,線性或框架? 然後我想在結果上使用開關盒,然後做this.getLayoutParams()
。如何找到視圖的佈局類型?
您可以使用instanceof
運算符。
if(view instanceof RelativeLayout) {
// do something
} else if(view instanceof LinearLayout) {
// do something
} else if(view instanceof FrameLayout) {
// do something
}