填充可以减少ImageView中的图标大小

填充可以减少ImageView中的图标大小

问题描述:

我想让我的图标产生连锁反应。但是,当我增加填充它减少图标的大小 当填充是5DP它看起来是这样的enter image description here填充可以减少ImageView中的图标大小

但是,当我增加填充的大小,以12dp它看起来像这样enter image description here

我的ImageView XML

<ImageView 
      android:id="@+id/institute_search_item_request_icon" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:layout_alignParentEnd="true" 
      android:layout_marginEnd="20dp" 
      android:layout_marginTop="15dp" 
      android:background="@drawable/request_institute_red_icon__shape" 
      android:foreground="@drawable/ripple_foreground" 
      android:padding="12dp" 
      android:src="@drawable/ic_link_white_24dp" /> 

request_institute_red_icon__shape.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="oval"> 

<solid android:color="@color/colorPrimary" /> 

和ripple_foreground.xml

<ripple xmlns:android="http://schemas.android.com/apk/res/android" 
android:color="@color/colorAccent"> 
<item android:id="@android:id/mask"> 
    <shape android:shape="oval"> 
     <solid android:color="@color/colorPrimary" /> 
    </shape> 
</item> 

+0

为什么你需要填充? –

+0

使用保证金做到这一点。 –

+0

@ Bhuvanesh我想要图标周围的波纹颜色。如果我犯了一些愚蠢的错误,请纠正我的错误 – FaisalAhmed

取出填充物,它会缩小你的图标。 在你imageview只需添加此行得到连锁反应

android:foreground="?attr/selectableItemBackground" 

要获得椭圆形波纹:

round_background.xml

<ripple xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:color="@color/colorAccent" 
    android:radius="your_radius" // try radius 
    tools:targetApi="lollipop"> 
    <item android:id="@android:id/mask"> 
     <shape android:shape="oval"> 
      <solid android:color="@color/colorPrimary" /> 
     </shape> 
    </item> 
    <item android:drawable="@drawable/red_background" /> 
</ripple> 

red_background.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid android:color="@color/red_color"/>/> 
</shape> 
+0

我已经试过了。它不会给我椭圆形的涟漪效应。它使用此解决方案以矩形形状出现 – FaisalAhmed

+0

试试我的更新回答 –

+0

它仍然显示矩形涟漪效应 – FaisalAhmed