android - 位图在 ImageView 上居中时出现问题

标签 android layout imageview center bmp

我在 xml 中有一个 ImageView (image_view) 并且我将布局重力设置为中心并将比例设置为 center_inside ....但是当我将压缩的 bmp 传递给 image_view 时,它将它放在中间 -屏幕左侧(纵向模式)...有什么解决方法吗?

这里是我将它设置为 ImageView :

        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"/>

最佳答案

您可以使用 FrameLayout 解决您的问题。

<强>

关于android - 位图在 ImageView 上居中时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4218372/

相关文章:

Android - 使图像的一部分在 android 中可重复?

android - Android 的密度桶之间的界限到底是什么?

java - 检查导航栏上的多个项目

android - 从 Alertdialog 启动另一个 Activity

css - 笔记本电脑与台式机的风格

CSS3 多列布局 IE 解决方法

java - Android 项目中 getResourceAsStream 的路径

android - 道路 googleapi : Some places missing and lines passing through edifices

WinForms:制作一组控件垂直缩放

java - 显示循环读取的第一个图像