无法将位图集中在ImageView上

时间:2010-11-18 18:47:14

标签: android layout imageview center bmp

我在xml中有一个ImageView(image_view),我将布局重力设置为居中,缩放设置为center_inside ....但是当我将压缩的bmp传递给image_view时,它将它放在中间位置 - 屏幕左侧(纵向模式)......有关解决方法的任何想法吗?

这是我将其设置为图像视图:

        ImageView imageView = (ImageView) findViewById(R.id.image_view);

        imageView.setImageBitmap(bitmap565);

我也在输出流中压缩它:

        try {
            FileOutputStream fos = new FileOutputStream(filepath);

            bitmap565.compress(CompressFormat.JPEG, 90, fos);

            fos.flush();
            fos.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

全部谢谢!

    <ImageButton android:id="@+id/ImageButton01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/results" android:layout_gravity="top|center"></ImageButton><ImageView
            android:screenOrientation="portrait"
            android:layout_width="fill_parent"
            android:id="@+id/image_view"
            android:layout_gravity="center" android:layout_weight="1.0" android:layout_height="wrap_content" android:scaleType="centerInside"/>

    <Button
            android:screenOrientation="portrait"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:textStyle="bold" android:id="@+id/detect_face" android:text="Detect"/>

2 个答案:

答案 0 :(得分:1)

您的ImageView layout_width设置为fill_parent,因此layout_gravity不会影响其父级中的水平位置。尝试使用gravity代替layout_gravity,或wrap_content代替fill_parent

答案 1 :(得分:1)

您可以使用FrameLayout解决问题。

<强>