2011-01-14 42 views
5

我已经知道如何在Android上获取我的Activity作为全屏,现在我需要在此屏幕上绘制图像。在FullScreen模式下绘制图像Android

这是我的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中绘制。

这是我的活动中的代码。

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是FullScreen,但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); 
} 

回答

7

添加android:scaleType="fitXY"imageview

+0

仍然无法使用。 – 2011-01-14 19:09:02

0

除了设置android:scaleType="fitXY",可以移除该活动标题栏使用这些方法之一的图像真正的全屏幕,使:

设置窗口首前setContentView()

requestWindowFeature(Window.FEATURE_NO_TITLE); 

或者在AndroidManifest文件中设置主题选项

android:theme="@android:style/Theme.NoTitleBar"