以下語句導致了程序異常,
GridLayout gridLayout = (GridLayout)findViewById(R.id.gridLayout);
參考鏈接,在XML中定義的gridLayout
與在程序中定義的gridLayout
不一致,導至了程序異常,改爲一致的定義,問題解決。
程序中的定義爲:
import android.widget.GridLayout;
然而XML中的定義爲:
androidx.gridlayout.widget.GridLayout
解決方案:
程序改爲以下:
androidx.gridlayout.widget.GridLayout gridLayout = findViewById(R.id.gridLayout);
額外的問題,layout
如果重疊,如何調整不同layout
的顯示順序,在Android Studio中的Component Tree
裏調整先後順序,就可以調整layout
顯示的優先級。