我在 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/