2017-08-04 2 views
0

J'ai une mise en page relative avec 3 enfants.layout_below ne fonctionne pas dans RelativeLayout

  • La première est la couverture ImageView.
  • 2ème est le centre de l'avatar ImageView dans le parent et
  • 3ème est le nom de l'application TextView ci-dessous l'avatar et le centre horizontal.

Comme en théorie cela devrait fonctionner mais ma mise en page ne place pas le texte ci-dessous avatar. Quel est le problème avec RelativeLayout? P/S: J'ai essayé les deux android:layout_below="@+id/logo2" et android:layout_below="@id/logo2" mais ne fonctionnait toujours pas!

Merci!

Voici ma mise en page xml.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:src="@drawable/android_apple"/> 

    <ImageView 
     android:id="@+id/logo2" 
     android:layout_width="64dp" 
     android:layout_height="64dp" 
     android:layout_centerInParent="true" 
     android:src="@drawable/default_avatar"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/logo2" 
     android:layout_centerHorizontal="true" 
     android:text="AAAAAAA" 
     android:textStyle="bold"/> 
</RelativeLayout> 

Et le résultat:

layout_below not working

Répondre

2

Modifier le parent de la hauteur de la mise en page relative au match parent. Ça va marcher.

Vous aimez cette

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:src="@drawable/android_apple" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
              /> 

    <ImageView 
     android:id="@+id/logo2" 
     android:layout_width="64dp" 
     android:layout_height="64dp" 
     android:layout_centerInParent="true" 
     android:src="@drawable/default_avatar"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/logo2" 
     android:layout_centerHorizontal="true" 
     android:text="AAAAAAA" 
     android:textStyle="bold"/> 
</RelativeLayout> 
+0

J'ai besoin de la hauteur de mise en page égale à la hauteur de couverture ImageView – phamxuanlu

+0

Vous devez afficher votre image de couverture à la pleine page droite? –

+0

La hauteur de ma couverture n'est pas complète. Et je veux utiliser seulement un RelativeLayout avec 3 enfants. Est-ce un bug de RelativeLayout? – phamxuanlu

0

essayer ci-dessous le code

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:src="@drawable/android_apple"/> 

    <ImageView 
     android:id="@+id/logo" 
     android:layout_width="64dp" 
     android:layout_height="64dp" 
     android:layout_centerInParent="true" 
     android:src="@drawable/default_avatar" 
     android:layout_margin="5dp"/> 

    <RelativeLayout 
     android:id="@+id/profile_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/logo" 
     android:elevation="4dp" 
     android:layout_marginTop="64dp"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="AAAAAAA" 
      android:textStyle="bold" 
      android:layout_margin="10dp" 
      android:layout_centerHorizontal="true"/> 
    </RelativeLayout> 
</RelativeLayout> 
0

essayer.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginStart="10dp" 
     android:adjustViewBounds="true" 
     android:src="@drawable/android_apple" /> 

    <ImageView 
     android:id="@+id/logo2" 
     android:layout_width="64dp" 
     android:layout_height="64dp" 
     android:layout_centerInParent="true" 
     android:src="@drawable/default_avatar" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignStart="@+id/logo2" 
     android:layout_below="@+id/logo2" 
     android:text="AAAAAAA" 
     android:textStyle="bold" /> 

</RelativeLayout> 
-1
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/logo2" 
    android:layout_centerHorizontal="true" 
    android:text="AAAAAAA" 
    android:textStyle="bold"/> 

Vous utilisez layout_below = "@ + id/logo2". Utilisez layout_below = "@ id/logo2", cela fonctionnera.

+0

ces choses sont les mêmes ne sont-ils pas? – Bryan

+1

@Vryin, non, ils ne sont pas. Reportez-vous à [this] (https://stackoverflow.com/questions/11160954/what-is-the-difference-between-id-and-id) – Kiya

+0

Je sais cela, et là je pensais que vous vouliez dire des choses différentes. Il devrait toujours fonctionner même avec + ou sans. – Bryan