Joh*_*han 123 android imageview
我有一个imageview
高度和宽度设置为fill_parent
具有linearlayout
相同值设置的.所以我想这应该设置我的图像以适应屏幕.但它只适合80%(横向模式中的上下边距).
我尝试了以下代码但没有成功:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
imgView.setMinimumWidth(width);
imgView.setMinimumHeight(height);
imgView.setMaxWidth(width);
imgView.setMaxHeight(height);
Run Code Online (Sandbox Code Playgroud)
还有其他想法吗?
Pin*_*nki 305
使用 imgview.setScaleType(ScaleType.FIT_XY);
Sen*_*Sen 118
在布局android:scaleType="fitXY"
PS 的xml文件中给出:这适用于设置图像时,android:src="..."
而不是android:background="..."
默认情况下设置的背景拉伸并适合视图.
Lal*_*mar 21
用这个:
ImageView.setAdjustViewBounds(true);
Run Code Online (Sandbox Code Playgroud)
小智 8
如果你使用android:scaleType="fitXY"
那么你必须指定
android:layout_width="75dp"
和 android:layout_height="75dp"
如果使用wrap_content,它将无法延伸到您需要的范围
<ImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:id="@+id/listItemNoteImage"
android:src="@drawable/MyImage"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginStart="12dp"
android:scaleType="fitXY"/>
Run Code Online (Sandbox Code Playgroud)