2017-07-31 73 views
0

,例如,如果一个80dp正方形布局包含一个较小的ImageView,ImageView的大小不会被缩放:如何在大于父级时将ImageView的大小独立于父级?

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="80dp" 
android:layout_height="80dp" 
android:background="#FFFF00" 
android:clipChildren="true"> 
<ImageView 
    android:adjustViewBounds="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@android:drawable/sym_def_app_icon" /> 
</RelativeLayout> 

enter image description here

但如果父比ImageView的较小的,例如:30DP:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="30dp" 
android:layout_height="30dp" 
android:background="#FFFF00" 
android:clipChildren="true"> 
<ImageView 
    android:adjustViewBounds="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@android:drawable/sym_def_app_icon" /> 
</RelativeLayout> 

它会被自动缩放:

enter image description here

,但我想要的ImageView的裁剪而不是缩放:

enter image description here

我怎样才能在XML这种作物的影响?

回答

0

有很多可用的技术。 尝试在你的ImageView XML添加这两种属性

android:scaleType="matrix" 

OR

Use margin-right,left,up,down. 

OR

Search Icon size in google and then edit this icon in photoshop give it a fix size of icon . 
0

尝试在您的ImageView XML

android:scaleType="matrix" 

添加以下属性希望它能帮助:)

相关问题