I have a bitmap which I am reading from a particular location on the device like such and am setting the image to an ImageView
scaledBitmap = BitmapFactory.decodeFile(selectedImagePath);
ivImage.setImageBitmap(scaledBitmap);
And thats how I am setting the xml code for that imageview
<ImageView
android:id="@+id/ivImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:scaleType="fitXY" />
Is there a way I can remove the blank space above the image inside the ImageView?
尝试将android:scaleType="fitXY"
更改为android:scaleType="centerCrop"
I had the same problem, and what I remember is removing adjustViewBounds attribute line from code will fix it. Try this and let me know.
scaleType="fitCenter"
(default when omitted)
scaleType="centerInside"
src
is smaller than parent width src
is larger than parent width It doesn't matter if you use android:src
or ImageView.setImage*
methods and the key is probably the adjustViewBounds
.
use this
<ImageView
android:id="@+id/ivImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:scaleType="centerCrop" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.