2014-10-04 62 views
0

有什麼辦法,如何把ImageView放在TextView上?我嘗試過很多方法,但TextView始終是「優先級」並顯示在頂部(在圖像上)。你有什麼想法,該怎麼做? (右邊綠色的文字 - 「DNES」 是的ImageView和 「博塔...」 是一個TextView) Whole layoutImageView在TextView上

XML佈局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="220dp" 
    android:minHeight="220dp" 
    android:padding="4dp" 
    android:background="@drawable/event_card" > 


    <ImageView 
     android:id="@+id/event_poster" 
     android:layout_width="match_parent" 
     android:layout_height="220dp" 
     android:src="@drawable/stub_img_new" 
     android:scaleType="centerCrop" /> 

    <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="90dp" 
    android:minHeight="90dp" 
    android:background="#D9F0F0F0" > 


    <cus.haw.sat.ImageViewRounded 
     android:id="@+id/event_club_logo" 
     android:layout_width="78dp" 
     android:layout_height="78dp" 
     android:scaleType="fitXY" 
     android:layout_marginLeft="5dp" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" /> 


    <cus.haw.sat.AutofitTextView 
     android:id="@+id/event_title" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_toRightOf="@id/event_club_logo" 
     android:textSize="17sp" 
     android:layout_marginLeft="7dp" 
     android:layout_marginRight="7dp" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="5dp" 
     android:maxLines="2" 
     android:textStyle="bold" /> 

     <cus.haw.sat.AutofitTextView 
     android:id="@+id/event_club_title" 
     android:layout_width="105dp" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/event_club_logo" 
     android:textSize="15sp" 
     android:layout_marginLeft="7dp" 
     android:gravity="bottom" 
     android:layout_marginRight="7dp" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="5dp" 
     android:maxLines="2" /> 

     <ImageView 
     android:id="@+id/event_today" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="fitXY" 
     android:layout_alignParentRight="true" 
     android:layout_marginLeft="7dp" 
     android:layout_marginRight="20dp" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="5dp" 
     android:src="@drawable/ic_today" 
     /> 

     <TextView 
     android:id="@+id/event_date" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:textSize="14sp" 
     android:layout_marginLeft="7dp" 
     android:layout_marginRight="7dp" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="5dp" 
     android:maxLines="3" /> 

    </RelativeLayout> 


    <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="29dp" 
    android:minHeight="39dp" 
    android:background="#D9F0F0F0" 
    android:layout_alignParentBottom="true" 
    android:paddingLeft="4dp" 
    android:paddingRight="4dp" > 

     <cus.haw.sat.AutofitTextView 
     android:id="@+id/event_bonus" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textSize="12sp" 
     android:gravity="center" 
     android:layout_centerInParent="true" 
     android:maxLines="2" /> 

    </RelativeLayout> 





</RelativeLayout> 
+0

是,使用的RelativeLayout或FrameLayout裏 – 2014-10-04 16:31:32

回答

3

RelativeLayoutFrameLayout孩子的順序控制Z軸。 後面的孩子(例如稍後在XML文件中)在Z軸上的高於。因此,如果您希望ImageView浮動在TextView之上,請確保ImageView的定義晚於TextView作爲相同RelativeLayout的子項。

+0

好了,謝謝你很多!但我有另一個問題:如果我切換視圖(ids:eventToday&eventDaty),ListView立即消失。你不知道哪裏可以解決問題? – marson 2014-10-04 16:45:10

+0

@marson:不是我的頭頂。通過模擬器使用層次結構視圖來確定發生了什麼。 – CommonsWare 2014-10-04 17:00:11

+0

感謝您的努力,它現在可以工作。我只是改變了textview的ID。 Idk爲什麼會發生這種情況。 – marson 2014-10-04 17:12:40

1

更改孩子下令: 「下面之後手段」

這應該工作;)