[英]Android Studio, wrap ImageView size around the x and y scale of the actual image
I have an ImageView
with a mail icon, however, it was too big so i reduced its size. 我有一个带有邮件图标的
ImageView
,但是它太大了,所以我减小了它的尺寸。 The actual size of the image is smaller, but the content it wraps is still the same , resulting in my lines not being even. 图像的实际尺寸较小,但包装的内容仍然相同 ,导致我的线条不均匀。 The image below demonstrates my problem
下图展示了我的问题
As you can see, the size of the imageview does not wrap around the image itself. 如您所见,imageview的大小不会环绕图像本身。 Below is the XML for the imageview
以下是imageview的XML
<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"/>
Is there a way to fix this? 有没有办法解决这个问题?
Below this is the full XML for the whole layout if that would help 如果可以帮助的话,下面是整个布局的完整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>
You should resize your image by giving it exact values for width and height instead of wrap_content
if you actually want the bounding box to get smaller as you change the size. 如果您确实希望边框在更改尺寸时变小,则应通过为图像提供宽度和高度的确切值而不是
wrap_content
来调整图像大小。 Then you can add padding/margins back to it as you wish. 然后,您可以根据需要向其添加填充/边距。 Also, you should use the
android:src
attribute (or maybe even app:srcCompat ) instead of android:background
. 另外,您应该使用
android:src
属性(甚至可能是app:srcCompat )而不是android:background
。
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@mipmap/ic_mail" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.