bottom-aligned LinearLayout TextView 中的 ImageView 标题未显示
ImageView caption in a bottom-aligned LinearLayout TextView not showing up
我有实现某种布局的需求。这些布局包含一个 ImageView,它是显示属于特定类别的电影的水平 RecyclerView 项目布局的一部分。
Desired layout screenshot
My current layout screenshot
The item layout for the RecyclerView containing the ImageView and
TextView label.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:background="@android:color/black">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imageViewMediaThumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:layout_gravity="top"
android:src="@mipmap/placeholder_image" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/clientMediaThumbnailLabel"
android:orientation="vertical">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:text="Movie Name"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
试试这个代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white" >
<TextView
android:id="@+id/movieTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="32sp"
android:text=""
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="left"/>
<ImageView
android:id="@+id/movieImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/movieTitle" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/movieTitle"
android:layout_centerHorizontal="true"
android:id="@+id/linearLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/textView"
android:layout_weight="1"
android:gravity="right" />
</LinearLayout>
我已经能够通过为 Image View 设置 20dp 的布局底部边距,同时减小 TextView 的文本大小(以避免它显示父布局右边距 space 更宽)来找到解决方案比图像)。
向图像视图添加 20dp 的底部边距使文本视图的文本变得可见。
这是我更新后的布局。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:background="@android:color/black">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/clientMediaThumbnailLabel"
android:orientation="vertical">
<ImageView
android:id="@+id/imageViewMediaThumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:layout_gravity="top"
android:src="@mipmap/placeholder_image"
android:layout_marginBottom="20dp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Movie Name"
android:textColor="@android:color/white"
android:textSize="10sp"
android:textStyle="bold" />
</RelativeLayout>
</android.support.v7.widget.CardView>
我有实现某种布局的需求。这些布局包含一个 ImageView,它是显示属于特定类别的电影的水平 RecyclerView 项目布局的一部分。
Desired layout screenshot
My current layout screenshot
The item layout for the RecyclerView containing the ImageView and TextView label.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:background="@android:color/black">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imageViewMediaThumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:layout_gravity="top"
android:src="@mipmap/placeholder_image" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/clientMediaThumbnailLabel"
android:orientation="vertical">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:text="Movie Name"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
试试这个代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white" >
<TextView
android:id="@+id/movieTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="32sp"
android:text=""
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="left"/>
<ImageView
android:id="@+id/movieImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/movieTitle" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/movieTitle"
android:layout_centerHorizontal="true"
android:id="@+id/linearLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/textView"
android:layout_weight="1"
android:gravity="right" />
</LinearLayout>
我已经能够通过为 Image View 设置 20dp 的布局底部边距,同时减小 TextView 的文本大小(以避免它显示父布局右边距 space 更宽)来找到解决方案比图像)。
向图像视图添加 20dp 的底部边距使文本视图的文本变得可见。
这是我更新后的布局。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:background="@android:color/black">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/clientMediaThumbnailLabel"
android:orientation="vertical">
<ImageView
android:id="@+id/imageViewMediaThumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:layout_gravity="top"
android:src="@mipmap/placeholder_image"
android:layout_marginBottom="20dp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Movie Name"
android:textColor="@android:color/white"
android:textSize="10sp"
android:textStyle="bold" />
</RelativeLayout>
</android.support.v7.widget.CardView>