我正在构建一个 Android 应用程序,它是为 Galaxy Tab 设计的,按规格,屏幕尺寸为 1024x600,但如果我尝试以这种尺寸添加我的组件,左侧和底部将被切断。
我添加了以下代码以查看差异
WindowManager mWMgr = (WindowManager) getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE);
int width = mWMgr.getDefaultDisplay().getWidth();
int height = mWMgr.getDefaultDisplay().getHeight();
Toast.makeText(getApplicationContext(),
"[system][w=" + width + ":h=" + height + "]", Toast.LENGTH_LONG).show();
width = getWindowManager().getDefaultDisplay().getWidth();
height = getWindowManager().getDefaultDisplay().getHeight();
Toast.makeText(getApplicationContext(),
"[this][w=" + width + ":h=" + height + "]", Toast.LENGTH_LONG).show();
运行时显示:[system][w=600:h=1024] [this][w=400:h=683]
为什么会发生?
如果需要,我添加我的代码以将组件放在屏幕上。
这是我的 layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:id="@+id/image01" android:layout_width="match_parent"
android:layout_height="match_parent" android:scaleType="fitXY" />
</LinearLayout>
在这种情况下,我在 ImageView 上绘制的图像会缩放到屏幕尺寸(400x683)
我测试过:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="600px"
android:layout_height="1024px">
<ImageView android:id="@+id/image01" android:layout_width="match_parent"
android:layout_height="match_parent" android:scaleType="fitXY" />
</LinearLayout>
并且通过这种方式,图像的左侧和底部被切断了屏幕。