ImageView在TextView上
有什么办法,如何把ImageView放在TextView上?我尝试过很多方法,但TextView始终是“优先级”并显示在顶部(在图像上)。你有什么想法,该怎么做? (右边绿色的文字 - “DNES” 是的ImageView和 “博塔...” 是一个TextView) ImageView在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>
的RelativeLayout
或FrameLayout
孩子的顺序控制Z轴。 后面的孩子(例如稍后在XML文件中)在Z轴上的高于。因此,如果您希望ImageView
浮动在TextView
之上,请确保ImageView
的定义晚于TextView
作为相同RelativeLayout
的子项。
好了,谢谢你很多!但我有另一个问题:如果我切换视图(ids:eventToday&eventDaty),ListView立即消失。你不知道哪里可以解决问题? – marson 2014-10-04 16:45:10
@marson:不是我的头顶。通过模拟器使用层次结构视图来确定发生了什么。 – CommonsWare 2014-10-04 17:00:11
感谢您的努力,它现在可以工作。我只是改变了textview的ID。 Idk为什么会发生这种情况。 – marson 2014-10-04 17:12:40
更改孩子下令: “下面之后手段”
这应该工作;)
是,使用的RelativeLayout或FrameLayout里 – 2014-10-04 16:31:32