Android:为什么在缩小后我的ImageView两侧都有白色填充? [英] Android : why do I have a white padding on two sides of my ImageView after down-scaling ?
本文介绍了Android:为什么在缩小后我的ImageView两侧都有白色填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道其他地方已经提到了这类问题。但我不明白为什么我在以下具体情况下遇到问题。这是非常简单的布局:
I know that this kind of questions has already been asked elsewhere. But I don't understand why I have got a problem in the following specific case. Here is the very simple layout:
<RelativeLayout
android:id="@+id/headerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#D0D0D0"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/appImageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="@+id/appNameTextView"
android:layout_alignTop="@+id/appNameTextView"
android:scaleType="centerInside"
android:src="@drawable/common_ic_googleplayservices"
android:background="#FF0000"
/>
<TextView
android:id="@+id/appNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/appImageView"
android:text="Here is some text"
android:textColor="#000000"
/>
</RelativeLayout>
结果如下:
< a href =https://i.stack.imgur.com/6J5X1.png =nofollow noreferrer>
common_ic_googleplayservices是一个缩小的方形图像。为什么我有一个填充(见红色区域)=>我的图像不再是正方形。
common_ic_googleplayservices is a square image which is scaled down. Why do I have a padding (see the red area) => my image is no more square.
如何解决问题? (请在给出答案前快速测试:))
How to solve the problem ? (please test quickly before giving an answer :) )
谢谢!!!
推荐答案
试试这个,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignTop="@+id/tv"
android:layout_alignBottom="@+id/tv"
android:src="@drawable/common_ic_googleplayservices" />
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/iv"
android:gravity="center_vertical"
android:text="TextView"
android:textSize="30dp"
/>
</RelativeLayout>
这篇关于Android:为什么在缩小后我的ImageView两侧都有白色填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文