2014-02-28 50 views
0

我試圖使一個疊加的高度取決於一個textview的重量。如下所示,我在背景中有一張圖片,並有一個半透明的疊加層,用作某些文本的背景。如何使疊加的高度取決於textview的高度?

enter image description here

我使用如下它包裝起來的背景圖像,覆蓋圖以及文字的FrameLayout:

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


<ImageView 
    android:id="@+id/image" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentTop="true" 
    android:scaleType="centerCrop" 
/> 

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom"> 
    <View 
      android:id="@+id/overlay" 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:background="@color/overlay_box_white"/> 
</FrameLayout> 

<TextView 
     android:id="@+id/userFeedHuntCardFrontSummary" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:layout_margin="10dp" 
     android:layout_gravity="bottom" 
     /> 

</FrameLayout> 

有誰知道如何使覆蓋框的高度在textview中有4dp的頂部和底部邊距?

謝謝!

回答

1

這個怎麼樣,我認爲它會做你所要求的?

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <ImageView 
     android:id="@+id/image" 
     android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentTop="true" 
    android:scaleType="centerCrop" 
    /> 
    <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:layout_marginTop="4dp" 
      android:layout_marginBottom="4dp" 
       android:background="@color/overlay_box_white"> 
    <TextView 
     android:id="@+id/userFeedHuntCardFrontSummary" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:layout_margin="10dp" 
     android:layout_gravity="bottom" 
     /> 
    </LinearLayout> 
</FrameLayout>