Mar*_*los 5 java android imageview android-layout
我已经知道如何在Android上将我的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>
Run Code Online (Sandbox Code Playgroud)
此图像是动态生成的,并在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);
}
Run Code Online (Sandbox Code Playgroud)
但是在运行时,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() + "]");
Run Code Online (Sandbox Code Playgroud)
这导致两种情况下[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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8825 次 |
| 最近记录: |