我有一个网格布局,我想在活动中显示任何内容之前检查其大小,因为我想检查图像是否需要调整大小。不能这样做 OnStart() 因为显然它还没有被加载。由于与其余代码的同步问题,添加侦听器不起作用。如果我可以通过使用设备的尺寸手动生成值,那就太好了,但我终生无法找到 Android 自动放置的那些愚蠢边距的确切值。有什么建议么?基本上在下面的代码中,我需要在调用 SplitImage() 之前获得 GridLayout 的高度/宽度。
XML
<GridLayout
android:id="@+id/grid_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:useDefaultMargins="false" >
</GridLayout>
相关JAVA
public class GamePlay extends Activity {
int difficulty = 0;
int image = 0;
int widthView = 0;
int heightView = 0;
int boardW;
int boardH;
int nSqr;
Bitmap[][] gameBoard;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Intent intent = getIntent();
difficulty = intent.getIntExtra("DIFFICULTY_KEY_DMIROU246", 0);
image = intent.getIntExtra("LEVEL_KEY_DMIROU246", 0);
setContentView(R.layout.activity_game_play);
Log.w("Derp", "1");
}
@Override
protected void onStart() {
super.onStart();
View view = (View) findViewById(R.id.grid_layout);
Log.w("Derp", "2");
heightView = view.getHeight();
widthView = view.getWidth();
Log.w("Derp", "3");
gameBoard = SplitImage();
Log.w("Derp", "9");
}