2015-11-10 2 views
0

je veux atteindre cet image 1Réglage de la largeur de imageview match de textview largeur

mais je m'y suis ce image 2

ici est ma mise en page

 <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@android:color/black"> 
     <ImageView 
      android:id="@+id/imf" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/frame001" 
      /> 

     <TextView 
      android:id="@+id/firetext" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="170dp" 
      android:text="Android" 
      android:textStyle="bold" 
      android:textColor="@android:color/white" /> 


    </RelativeLayout> 

est-il possible à l'échelle la largeur de imageview pour mettre à l'échelle la largeur du texte vu que le texte dans le textview est dynamique

+0

Je n'ai pas le temps d'écrire du code maintenant, mais vous pouvez prendre la taille du texte de la largeur et la largeur d'image réglée selon la largeur du texte ... voir ceci: http://stackoverflow.com/questions/21926644/ get-height-and-width-of-a-layout-programatically – AsfK

+0

Utilisez les règles leftOf et RightOf de relativeLayout. Considérez aussi ceci: http://stackoverflow.com/questions/29956014/why-should-we-use-xml-layouts – Nanoc

+1

Il suffit d'utiliser un ** composable drawable ** dans votre TextView (et se débarrasser de l'ImageView): mieux performances, design plus plat, très facile à mettre en œuvre. 'android: drawableTop =" @ drawable/frame001 "' –

Répondre

0

Je pense que cela fonctionnera, mais je ne l'ai pas essayé.

<LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@android:color/black" 
      android:orientation="vertical"> 
      <ImageView 
       android:id="@+id/imf" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:src="@drawable/frame001" 
       /> 

      <TextView 
       android:id="@+id/firetext" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="170dp" 
       android:text="Android" 
       android:textStyle="bold" 
       android:textColor="@android:color/white" /> 


     </LinearLayout> 
0
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@android:color/black"> 
    <ImageView 
     android:id="@+id/imf" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/frame001" 
     android:layout_alignLeft="@+id/firetext" 
     android:layout_alignRight="@+id/firetext" /> 

    <TextView 
     android:id="@+id/firetext" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="170dp" 
     android:text="Android" 
     android:textStyle="bold" 
     android:textColor="@android:color/white" />