2015-11-10 3 views
0

я хочу достичь этой image 1набор ширина ImageView матч TextView ширина

, но я получил это image 2

вот мой макет

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

есть ли способ масштабирования ширины ImageView для масштабирования ширины текста, учитывая, что текст в текстовом виде является динамическим

+0

У меня нет времени, чтобы написать код сейчас, но вы можете взять размер текста по ширине и установить ширину изображения в соответствии ширины текста ... увидеть это: http://stackoverflow.com/questions/21926644/ get-height-and-width-of-a-layout-programatically – AsfK

+0

Используйте правила leftOf и RightOf для параметра relativeLayout. Также подумайте об этом: http://stackoverflow.com/questions/29956014/why-should-we-use-xml-layouts – Nanoc

+1

Просто используйте ** составную ** выталкиваемую ** в текст TextView (и избавитесь от ImageView): лучше исполнение, более плоский дизайн, очень прост в реализации. 'Андроид: drawableTop = "@ вытяжка/frame001"' –

ответ

0

Я думаю, что это сработает, но я не пробовал.

<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" /> 
Смежные вопросы