2017-01-19 2 views
0

J'ai un ImageView aligné à droite d'un TextView. Lorsque le texte est trop long, il redimensionne l'image ... Comment puis-je conserver la même taille pour l'image et forcer le TextView sur une nouvelle ligne?Impossible de réparer ImageView à l'intérieur de RelativeLayout

texte court, de bonne taille:
enter image description here

Texte long, mauvaise taille:
enter image description here

Voici le XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:background="@color/md_white_1000" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <RelativeLayout 
     android:id="@+id/btn_container_1" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:background="@color/blue" 
     android:layout_weight=".50" 
     android:layout_marginRight="1dp"> 

     <Button 
      android:id="@+id/btn_1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:alpha="0" 
      android:onClick="searchClicked"/> 

     <TextView 
      android:id="@+id/btn_text_1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:textColor="@color/md_white_1000" 
      android:paddingEnd="10dp" 
      android:paddingRight="10dp" 
      android:text="BTN1" /> 

     <ImageView 
      android:id="@+id/btn_image_1" 
      android:layout_width="28dp" 
      android:layout_height="28dp" 
      android:layout_centerVertical="true" 
      android:layout_toEndOf="@id/btn_text_1" 
      android:layout_toRightOf="@id/btn_text_1" 
      android:layout_marginTop="2dp" 
      android:layout_marginBottom="2dp" 
      android:src="@drawable/draw" /> 
    </RelativeLayout> 
</LinearLayout> 
+0

essayez android: ellipsize = "fin" dans la balise Textview – Onkar

Répondre

1

Vous pouvez ajouter une disposition linéaire imbriquée de le faire comme ce qui suit:

<RelativeLayout 
    android:id="@+id/btn_container_1" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:background="@color/blue" 
    android:layout_weight=".50" 
    android:layout_marginRight="1dp"> 

    <Button 
     android:id="@+id/btn_1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:alpha="0" 
     android:onClick="searchClicked"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     > 

     <TextView 
      android:id="@+id/btn_text_1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:layout_gravity="center" 
      android:textColor="@color/md_white_1000" 
      android:paddingEnd="10dp" 
      android:paddingRight="10dp" 
      android:text="BTN1" /> 

     <ImageView 
      android:id="@+id/btn_image_1" 
      android:layout_width="28dp" 
      android:layout_height="28dp" 
      android:layout_gravity="center" 
      android:layout_marginTop="2dp" 
      android:layout_marginBottom="2dp" 
      android:src="@drawable/draw" /> 

    </LinearLayout> 
</RelativeLayout> 
1

Je pense que vous devriez utiliser la mise en page linéaire avec orientation horizontale au lieu de la mise en page relative et définir le poids à la fois pour textview et imageview.

0

ne codent pas difficile tout attribut il va créer problème au point plus tard si des changements de taille de l'écran essayer cette

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:gravity="center" 
    android:weightSum="1" 
    android:layout_marginTop="100dp" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

     <Button 
      android:id="@+id/btn_1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:alpha="0" 
      android:text="button" 
      android:layout_weight="0.2" 
      android:onClick="searchClicked"/> 

     <TextView 
      android:id="@+id/btn_text_1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:textColor="@color/colorPrimary" 
      android:layout_weight="0.4" 
      android:text="BTN1" /> 

     <ImageView 
      android:id="@+id/btn_image_1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.4" 
      android:src="@drawable/state" /> 
</LinearLayout> 
0
Can you try this, if it is not working send me you screen how you want to design.I will help you. 

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    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" 
    tools:context="est.androidapplication.MainActivity"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:background="#00f" 
     android:weightSum="1"> 
     <TextView 
      android:id="@+id/btn_text_1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:layout_gravity="center" 
      android:gravity="center" 
      android:textColor="#ff0044" 
      android:paddingEnd="10dp" 
      android:paddingRight="10dp" 
      android:text="BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1" /> 

     <ImageView 
      android:id="@+id/btn_image_1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:layout_gravity="center" 
      android:gravity="center" 
      android:src="@mipmap/ic_launcher" /> 
    </LinearLayout> 
</RelativeLayout> 
0

utiliser le poids de textview dans la disposition linéaire.

<?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"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:layout_margin="10dp" 
    android:layout_centerVertical="true"> 

    <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:gravity="center" 
    android:text="BTN1"/> 
    <ImageView 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
     android:layout_marginLeft="10dp" 
     android:background="#344"/> 

</LinearLayout> 


</RelativeLayout>