【发布时间】:2018-01-02 00:30:28
【问题描述】:
我创建了一个项目 XML 文件,我想将它传递给 Adapter,以便在 RecyclerView 中显示项目列表。
布局文件由一个CardView 组成,其中包含一个用于显示电影海报的ImageView 和一个用于显示电影标题的TextView。
我的问题是我找不到将TextView 放在ImageView 上的方法,因此可以在海报上方看到标题。
我的 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="wrap_content"
android:layout_margin="@dimen/dimension_value_10"
>
<android.support.v7.widget.CardView
app:cardCornerRadius="@dimen/dimension_value_5"
android:layout_width="match_parent"
android:layout_height="200dp"
android:elevation="@dimen/dimension_value_15"
android:id="@+id/movie_poster_card"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<ImageView
android:id="@id/movie_poster_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="10dp" />
<TextView
android:id="@+id/movie_title_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/movie_poster_card"
android:layout_centerHorizontal="true"
android:gravity="center|start"
android:layout_margin="@dimen/dimension_value_10"
android:paddingLeft="@dimen/dimension_value_10"
android:text="Movie title here"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:textSize="26sp" />
</android.support.v7.widget.CardView>
这里是更明确的设计图片:
【问题讨论】:
-
在cardview中使用相对布局,并将imageview和textview放在相对布局中。
-
[这可能会解决你的问题...](stackoverflow.com/questions/26976135/…)
-
[这可能会解决你的问题...](stackoverflow.com/questions/26976135/…)
-
是的,这解决了。谢谢
标签: android textview imageview overlay cardview