2017-08-25 1 views
0

Je sais comment créer fond ovale, ajouter cette drawable à un arrière-plan RelativeLayout:Android faire fond ovale drawable avec coin le chat

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" android:padding="10dp"> 
    <solid android:color="#FFFFFF"/> 
    <corners 
     android:bottomRightRadius="15dp" 
     android:bottomLeftRadius="15dp" 
     android:topLeftRadius="15dp" 
     android:topRightRadius="15dp"/> 
</shape> 

Mais je veux créer cette étirables et le coin d'une discussion comme celui-ci :

oval image

Comment puis-je ajouter à ce drawable le coin de la discussion?

+0

Vous avez probablement utiliser un '9- image de patch' pour ce –

+0

Je ne sais pas ce qui est 9-patch, mais j'ai besoin tha t échelle de mise en page avec des lignes de texte. – user2983041

+0

@ user2983041 J'ai posté une solution. Faites-moi savoir si cela ne fonctionne pas –

Répondre

2

Créez votre mise en page de bulles comme ce

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_margin="16dp" 
    android:orientation="vertical"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Hello" 
     android:padding="16dp" 
     android:background="@drawable/rounded_rect"/> 

    <ImageView 
     android:layout_marginTop="-1.5dp" 
     android:layout_width="8dp" 
     android:layout_height="16dp" 
     android:layout_gravity="start" 
     android:background="@drawable/corner" 
     /> 

</LinearLayout> 

fichiers Drawable

de rounded_rect.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid android:color="#888" /> 
    <corners 
     android:bottomRightRadius="8dp" 
     android:topLeftRadius="8dp" 
     android:topRightRadius="8dp"/> 

</shape> 

corner.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <rotate 
      android:fromDegrees="45" 
      android:pivotX="135%" 
      android:pivotY="15%" 
      android:toDegrees="45" 
      > 
      <shape android:shape="rectangle"> 
       <solid android:color="#888"/> 

      </shape> 
     </rotate> 
    </item> 
</layer-list> 

Cette disposition va évoluer avec le texte que vous ajoutez à la TextView

EDIT

Je viens maintenant remarqué que la flèche de votre exigence devrait pointer vers la gauche. Pour obtenir ce faire quelques petits changements à votre mise en page de la bulle

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="16dp" 
    android:orientation="horizontal"> 

    <ImageView 
     android:layout_width="12dp" 
     android:layout_height="12dp" 
     android:layout_gravity="bottom" 
     android:background="@drawable/corner2" 
     /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Hello" 
     android:padding="16dp" 
     android:background="@drawable/rounded_rect"/> 

</LinearLayout> 

corner2.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <rotate 
      android:fromDegrees="-45" 
      android:pivotX="135%" 
      android:pivotY="15%" 
      android:toDegrees="45" 
      > 
      <shape android:shape="rectangle"> 
       <solid android:color="#888"/> 

      </shape> 
     </rotate> 
    </item> 
</layer-list> 

SORTIE

enter image description here

+0

Ne fonctionne pas, je ne vois pas le coin. – user2983041

+0

Lequel avez-vous essayé? celui qui utilise 'corner1.xml' ou' corner.xml' –

+0

@ user2983041 Êtes-vous sûr d'avoir utilisé le fichier dessinable exactement comme je l'ai fait? Ça devrait marcher. –

1

Vous devriez faire un dessin de la Bulle de Chat complète, y compris les coins. Ensuite, faites-en un 9-patch afin que l'étirable se déploie horizontalement et verticalement sans se déformer.