1

J'essaie d'obtenir la capture d'écran suivante dans android.Mettre une image dans une autre image sous Android

enter image description here

Pour obtenir une image ronde je image ronde Bibliothèque d'ici:

https://github.com/vinc3m1/RoundedImageView

J'ai donc essayé le code suivant:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:background="@drawable/marker" 
android:orientation="horizontal" > 

<com.ylg.RoundImageView 
     android:id="@+id/profilePhoto" 
     android:layout_width="80dp" 
     android:layout_height="80dp" 
     android:gravity="center_horizontal" 
     android:src="@drawable/profilepic" /> 

mais je fini par avoir une erreur :

NOTE: This project contains Java compilation errors, which can cause rendering failures for custom views. Fix compilation problems first. 

Exception raised during rendering: Index: 0, Size: 0 

J'ai besoin 9 patch pour mon image marqueur: Ce que je l'ai fait ci-dessous:

enter image description here

Quoi de mal ici. Comment puis-je obtenir la capture d'écran abouve dans ma mise en page xml?

Répondre

2

juste jouer avec marge pour l'adapter exactement:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:orientation="vertical" 
    > 

    <RelativeLayout 
     android:layout_width="130dip" 
     android:layout_height="130dip" 
     android:background="@drawable/bg" > 

     <com.example.mmlooloo.RoundedImageView 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/imageView1" 
      android:layout_width="90dip" 
      android:layout_height="90dip" 
      android:layout_centerHorizontal="true" 
      android:layout_marginBottom="15dip" 
      android:layout_marginTop="10dip" 
      android:scaleType="centerCrop" 
      android:src="@drawable/profile" 
      app:border_color="#0000FF" 
      app:border_width="2dip" 
      app:corner_radius="80dip" 
      app:oval="true" /> 
    </RelativeLayout> 

</LinearLayout> 

et:

<resources> 

    <!-- Default screen margins, per the Android Design guidelines. --> 
    <dimen name="activity_horizontal_margin">16dp</dimen> 
    <dimen name="activity_vertical_margin">16dp</dimen> 

</resources> 

résultat:

enter image description here

+0

Merci beaucoup. Cela a résolu le problème pour moi. J'ai ajouté peu changé à mon pic de neuf chemin pour s'adapter à l'image correctement. Tout fonctionne bien maintenant .. – TheDevMan

3

Vous ne pouvez pas utiliser FrameLayout comme ça?

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.testproject.MainActivity" > 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/bg" > 
    </ImageView> 

    <ImageView 
     android:id="@+id/overlay" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/ic_launcher"/> 

</FrameLayout> 

J'ai utilisé l'image de la frontière comme @drawable/bg et je reçois cette sortie:

enter image description here

Dans votre cas, l'image de l'utilisateur sera plus petite que l'image de la frontière, ce qui devrait s'adapter.

Espérons que cela aide. Essayez de définir l'arrière-plan de ImageView sur une ressource pouvant être dessinée (xml) contenant l'image d'arrière-plan et définissez ImageView src sur l'image de votre choix.

+0

Je reçois quelque chose comme ceci: http://img42.com/SsRk8 – TheDevMan

+0

@TheDevMan Pouvez-vous montrer votre layout.xml? –

+0

Vérifiez la réponse modifiée. J'ai ajouté ce que je reçois @TheDevMan –

0

Cela devrait résoudre votre problème.

EDIT

Essayez ce code

<ImageView 
     android:id="@+id/img_chatUserImg" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     android:background="@drawable/bb" 
     android:paddingBottom="40.0dip" 
     android:paddingTop="10.0dip" 
     android:paddingRight="10.0dip" 
     android:paddingLeft="10.0dip" 
     android:src="@drawable/ic_smiley"/> 

où 'bb' est l'image blanche backgournd et src contient l'image réelle tat est affiché au-dessus.

enter image description here

J'ai ajusté mon rembourrage en conséquence.Si la taille de l'image varie alors enveloppez l'image dans un autre LinearLayout et réglez l'arrière-plan et le rembourrage et placez la vue de l'image à l'intérieur et fixez la taille de sorte qu'il reste toujours à l'intérieur de la bordure blanche

+0

Pouvez-vous me donner un exemple? – TheDevMan

+0

@TheDevMan J'ai édité la réponse, vérifiez-la – Panther

+0

@ Panther: Le problème ici est que je veux que ma photo de profil soit arrondie et donc j'appelle la bibliothèque RoundImageView. Si j'utilise le fond je ne peux pas réaliser ce qui est requis. – TheDevMan

Questions connexes