2017-09-28 17 views
-1

Fondamentalement, il existe un RelativeLayout et deux vues enfant (TextViews). L'un d'un enfant a une largeur plus grande que l'autre (cela dépend du contenu de la largeur de l'enfant cos définie sur "wrap_content"). Comment déplacer le plus petit téléviseur, que sa bordure droite correspond à la bordure droite de son conteneur (RL)? Situation SituationAligner les vues enfant à l'intérieur de RelativeLayout pour correspondre à la bordure droite du parent

désiré alocation Desired alocation

XML:

<RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:gravity="right" 
     > 
    <TextView 
     android:id="@+id/effect_text" 
     android:textSize="100sp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:textStyle="bold" 
     android:textColor="@color/transparent_color" 
     android:text="88:88" 
     /> 
     <TextView 
      android:id="@+id/text" 
      android:textSize="100sp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textStyle="bold" 
      android:shadowColor="@color/text_shadow" 
      android:shadowDx="1" 
      android:shadowDy="1" 
      android:shadowRadius="10" 
      android:text="12:34"/> 
    </RelativeLayout> 
+0

montrer votre fichier layout.xml à la question –

Répondre

0

essayer ce juste faire votre deuxième textviewandroid:layout_toRightOf="@+id/effect_text" à votre première Textview

comme ci-dessous le code

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <TextView 
     android:id="@+id/effect_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:text="88:88" 
     android:textColor="@color/transparent_color" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="5dp" 
     android:layout_toRightOf="@+id/effect_text" 
     android:shadowColor="@color/text_shadow" 
     android:shadowDx="1" 
     android:shadowDy="1" 
     android:shadowRadius="10" 
     android:text="12:34" 
     android:textStyle="bold" /> 


</RelativeLayout> 
+0

android: layout_toRightOf = "@ + id/effect_text" fait frontière gauche du deuxième match TV bordure droite de la première TV. Ne fonctionne pas :( –

+0

essayer d'ajouter un peu de ** android: layout_marginLeft = "5dp" ** à votre deuxième textview @oleg_phorostyna –

+0

Je vois l'utilisation de la marge codée en dur est seulement une solution –

1

L'avez-vous écrit de cette manière?

<TextView 
    android:id="@+id/effect_text" 
    android:textSize="100sp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:textStyle="bold" 
    android:textColor="#fbb" 
    android:text="88:88" 
    /> 
<TextView 
    android:id="@+id/text" 
    android:textSize="100sp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:textStyle="bold" 
    android:textColor="#abb" 
    android:shadowDx="1" 
    android:shadowDy="1" 
    android:shadowRadius="10" 
    android:text="12:34"/> 
+0

Ne fonctionne pas Et il me surprend. mais ce moyen ne me satisfait pas. –

0

Essayez cette

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="right"> 

    <TextView 
     android:id="@+id/effect_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="88:88" 
     android:layout_toLeftOf="@id/text" 
     android:textColor="@android:color/black" 
     android:textSize="100sp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/text" 
     android:layout_alignParentRight="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:shadowColor="@color/text_shadow" 
     android:shadowDx="1" 
     android:layout_marginLeft="8dp" 
     android:shadowDy="1" 
     android:shadowRadius="10" 
     android:text="12:34" 
     android:textSize="100sp" 
     android:textStyle="bold" /> 
</RelativeLayout>