我有this animation/code,其中点按照片将其放大到全屏,而屏幕的其余部分变黑。当我使用this banana照片时,尺寸变得足够大。 但是,当我使用API从网络中提取图片时,图片变得非常小我尝试检查图片的大小,但这似乎并不那么自然。从源下载时,water bottle image实际上是h:89和w:273像素。
//pulling the image and finding its sizes
Glide.with(getContext()).load(currentFood.getImageUrl()).into(ivFullScreen);
int ih=ivFullImage.getMeasuredHeight();//height of imageView = 1440
int iw=ivFullImage.getMeasuredWidth();//width of imageView = 2464
int iH=ivFullImage.getDrawable().getIntrinsicHeight();//original height of underlying image = 3332
int iW=ivFullImage.getDrawable().getIntrinsicWidth();//original width of underlying image = 4442
Toast.makeText(getContext(), "view height: " + ih + " view width: " + iw + " image height: " + iH + " image width: " + iW, Toast.LENGTH_LONG).show();
The Toast showed that the `ivFullImage` size is h:1440 and w:2464 and the image's size is h:3332 and w:4442.
XML:
<LinearLayout android:id="@+id/llFullScreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:alpha="0.0">
</LinearLayout>
<ImageView android:id="@+id/ivFullImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/bananas1"
android:scaleType="centerInside"
android:visibility="invisible"
/>
答案 0 :(得分:1)
尝试将android:adjustViewBounds="true"
属性添加到ImageView
:
<ImageView android:id="@+id/ivFullImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/bananas1"
android:scaleType="centerInside"
android:adjustViewBounds="true" />
更多信息:ImageView
答案 1 :(得分:0)
如果仿真器/设备尺寸太大,图像看起来很小可能很自然。尽管如此,我可以看到您使用android:src="@drawable/bananas1"
从XML静态添加图像,而不是动态地从代码中添加图像。如果您想从互联网上下载图像并添加它,您可以从代码中调用布局的ImageView,然后从您拥有的URL中获取要添加的图像
ImageView mImage = (ImageView) findViewById(R.id.ivFullImage);
//get the image from the url using the library you have, convert to bitmap
mImage.setImageBitmap(yourImageInBitmap);
此外,在您的XML中,您需要定义ImageView的宽度和高度,以通过说
来调整您要插入的图像的尺寸android:layout_width="wrap_content"
android:layout_height="wrap_content"