2017-09-01 1 views
0

Je veux un effet d'entraînement sur mon icône. Mais quand j'augmenter le rembourrage, il réduit la taille de l'icône lorsque le remplissage est 5DP il ressemble à ceci enter image description hereRembourrage réduit la taille de l'icône dans ImageView

Mais quand j'augmenter la taille de rembourrage à 12dp il ressemble à ce enter image description here

Mon 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" /> 

et 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

Pourquoi avez-vous besoin de rembourrage? –

+0

utiliser la marge faire cela. –

+0

@ Bhuvanesh je veux onduler la couleur autour de l'icône. Corrigez-moi si je fais une erreur stupide – FaisalAhmed

Répondre

0

Retirez le rembourrage, il rétrécira votre icône. En vous imageview Il suffit d'ajouter cette ligne pour obtenir un effet d'entraînement

android:foreground="?attr/selectableItemBackground" 

Pour ondulation ovale:

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

Je l'ai déjà essayé. Il ne me donne pas l'effet d'ondulation de forme ovale. Il apparaît en forme de rectangle en utilisant cette solution – FaisalAhmed

+0

Essayez ma mise à jour –

+0

encore il montre effet d'ondulation rectangle – FaisalAhmed