Android Studio,将ImageView大小环绕实际图像的x和y比例
我有一个带有邮件图标的ImageView,但是它太大了,所以我缩小了它的大小。 图像的实际大小较小,但它包装的内容仍然相同,导致我的线条不均匀。下图显示了我的问题 如您所见,imageview的大小并不环绕图像本身。 下面是imageview的XMLAndroid Studio,将ImageView大小环绕实际图像的x和y比例,android,Android,我有一个带有邮件图标的ImageView,但是它太大了,所以我缩小了它的大小。 图像的实际大小较小,但它包装的内容仍然相同,导致我的线条不均匀。下图显示了我的问题 如您所见,imageview的大小并不环绕图像本身。 下面是imageview的XML <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:backg
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/ic_mail"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:scaleX="0.5"
android:scaleY="0.5"/>
有办法解决这个问题吗
下面是整个布局的完整XML(如果有帮助的话)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/PaleGrey">
<Space
android:id="@+id/dummyTopSpaceSc"
android:layout_width="wrap_content"
android:layout_height="10dp"
android:layout_alignParentTop="true"/>
<TextView
android:id="@+id/nameTextView"
android:paddingLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/dummyTopSpaceSc"
android:text="name"
android:textStyle="bold"/>
<TextView
android:id="@+id/titleTextView"
android:layout_width="wrap_content"
android:paddingLeft="10dp"
android:layout_height="wrap_content"
android:layout_below="@+id/nameTextView"
android:text="title"/>
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/titleTextView"
android:id="@+id/phoneContainer">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/ic_phone"
android:scaleType="fitCenter"
android:scaleX="0.5"
android:scaleY="0.5"/>
<TextView
android:id="@+id/phoneTextView"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
app:layout_marginLeftPercent="15%"
android:layout_height="wrap_content"
android:autoLink="phone"
android:text="phone"/>
</android.support.percent.PercentRelativeLayout>
<!-- below this comment is the container for the mail icon -->
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/mailContainer"
android:layout_below="@+id/phoneContainer">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/ic_mail"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:scaleX="0.5"
android:scaleY="0.5"/>
<TextView
android:id="@+id/emailTextView"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
app:layout_marginLeftPercent="15%"
android:layout_height="wrap_content"
android:autoLink="email"
android:text="email"/>
</android.support.percent.PercentRelativeLayout>
<Space
android:id="@+id/dummyBottomSpaceSc"
android:layout_width="wrap_content"
android:layout_height="10dp"
android:layout_below="@id/mailContainer"/>
</RelativeLayout>
如果您确实希望在更改大小时边界框变小,则应通过为图像指定精确的宽度和高度值来调整图像大小,而不是包裹内容。然后,您可以根据需要将填充/边距添加回它。此外,您应该使用android:src属性,或者甚至可以使用android:background来代替
图像是否有空格??尝试删除比例。如果我删除比例,它会占用整个区域,但看起来太大,那么您需要指定尺寸或重新创建图像。谢谢,在背景上使用src有什么好处?背景是视图基类的属性,而src是您要使用的ImageView的属性。我认为用背景来代替,最终会导致一些奇怪的行为。设置src属性相当于从Java代码调用setImageDrawable。这里有一个很好的总结:
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@mipmap/ic_mail" />