我已经知道如何在安卓上将我的Activity设置为全屏,现在我需要在这个屏幕上绘制一张图片。
这是我的XML布局。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/image01" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
这张图片是在ImageView中动态生成并绘制的。
以下是我在Activity中的代码:
public void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
但是当运行时,Activity是全屏的,但是ImageView却在中心调整。
出了什么问题?
我添加了以下代码以查看组件的尺寸。
View view = getWindow().getDecorView();
Log.i("RMSDK:J:IbaReader(decor)",
"[w=" + view.getWidth() + ":h=" + view.getHeight() + "]");
Log.i("RMSDK:J:IbaReader(img)",
"[w=" + img.getWidth() + ":h=" + img.getHeight() + "]");
在这两种情况下,结果均为[w=320:h=480]。
这是我的绘图方法。
private void draw() {
byte[] image = services.getImageBuffer(600, 1024);
Bitmap bmp = Bitmap.createBitmap(600, 1024, Bitmap.Config.RGB_565);
int row = 0, col = 0;
for (int i = 0; i < image.length; i += 3) {
bmp.setPixel(col++, row, image[i + 2] & image[i + 1] & image[i]);
if (col == 600) {
col = 0;
row++;
}
}
img.setImageBitmap(bmp);
}