Trouble centering a bitmap on an ImageView
I have an ImageView (image_view) in an xml and I have the layout gravity set to center and the scale set to center_inside....but when I pass my compressed bmp to the image_view, it puts it on the middle-left of the screen (in portrait mode)...any ideas on a workaround?
here is me setting it to the image view:
ImageView imageView = (ImageView) findViewById(R.id.image_view);
imageView.setImageBitmap(bitmap565);
I also compress it in an output stream:
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();
}
Than开发者_运维知识库ks all!
<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"/>
you can solve your problem just using FrameLayout.
Your ImageView
's layout_width
is set to fill_parent
, so layout_gravity
won't affect its horizontal position within its parent. Try using gravity
instead of layout_gravity
, or wrap_content
instead of fill_parent
.
精彩评论