android imageview包装内容
大家好,谢谢你们的帮助 我在安卓工作室有一个项目 我在垂直线性布局中使用ImageView 这是我的参数android imageview包装内容,android,imageview,width,fill-parent,Android,Imageview,Width,Fill Parent,大家好,谢谢你们的帮助 我在安卓工作室有一个项目 我在垂直线性布局中使用ImageView 这是我的参数 <ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/imageView2" android:src="@drawable/myimg" /> 您可以在下面看到我的图像(红色块)和imageview
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:src="@drawable/myimg"
/>
您可以在下面看到我的图像(红色块)和imageview边框(蓝色线)
宽度没有问题,它是我布局的100%,但我希望我的图像适合该区域,同时保持纵横比。正如您在图像中看到的,存在空白,ImageView高度比我的图像大,如何在ImageView中调整图像
我想要这个,因为我想要的图像适合宽度,即使手机是纵向或横向的
图像视图的大小正确。您必须相应地缩放图像。
imageview
具有缩放属性。请尝试此android:scaleType=“fitXY”
让我知道。您的代码是编写的,但我不知道父布局,您的图像背景是白色的,而红色部分位于背景的中间
下面是与父布局相关的代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/red"
/>
对于
ImageView
,android:scaleType=“fitXY”
将丢失aspectration。最好使用android:scaleType=“fitCenter”并将图像视图的背景设置为透明的
如果您不想保留aspectration,则setbackground()
或fitxy
将满足您的要求在imageview中,有一个中心裁剪选项-
android:scaleType="centerCrop"
它将做的是从中心裁剪图像。输出将类似于-
我找到了解决办法
android:adjustViewBounds=“true”
使用android:src,而不是使用android:background,然后检查。它可能会根据需要获得所需的效果。当我使用“fitXY”时,我的图像的纵横比正在改变,我的图像看起来很糟糕。你救了我一命