android - 将 TextView 放在具有高度的图像视图之上
问题描述
我已经对堆栈溢出进行了广泛的研究,但没有找到适合我的答案。我所拥有的是ImageView
一个elevation
(用于阴影效果)在我想要一个TextView
. 我将对 a 中的许多元素重复此操作GridLayout
,因此bringToFront()
看起来不是一个好的选择。此外,我不希望TextView
有阴影,因此 的translationZ
属性xml
也不起作用。最后,我尝试将 aFrameLayout
用于这两个元素,但我认为由于 上的海拔属性Imageview
,TextView
仍然保留在后面。以下是我的代码
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="2"
android:layout_column="0"
android:layout_row="0"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
app:cardElevation="8dp"
app:cardCornerRadius="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:gravity="center">
<TextView
android:id="@+id/bids_number"
android:background="@drawable/circulerimageblue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:layout_marginBottom="-7dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingTop="1dp"
android:paddingBottom="1dp"
android:textStyle="normal|bold"
android:textColor="@color/colorSecondary"
android:layout_gravity="top|right" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:elevation="6dp"
android:id="@+id/bids_icon"
android:background="@drawable/circulerimageunselected"
android:layout_marginBottom="6dp"
android:src="@drawable/icon_profile"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Bids"
android:textAppearance="@style/TextAppearance.AppCompat"
android:textStyle="normal|bold"
android:fontFamily="sans-serif" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
这是我想要达到的目标的图片
解决方案
注意:请不要使用负边距
试试这个使用CoordinatorLayout
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_row="0"
android:layout_rowWeight="2"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/topPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/bids_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="6dp"
android:adjustViewBounds="true"
android:elevation="6dp"
android:scaleType="fitXY"
android:src="@drawable/kid" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Bids"
android:textAppearance="@style/TextAppearance.AppCompat"
android:textStyle="normal|bold" />
</LinearLayout>
<TextView
android:layout_width="20dp"
android:layout_height="wrap_content"
android:background="@color/colorPink"
android:text="10"
android:textStyle="normal|bold"
app:layout_anchor="@+id/bids_icon"
app:layout_anchorGravity="right" />
</android.support.design.widget.CoordinatorLayout>
</android.support.v7.widget.CardView>
输出
推荐阅读
- perl - setAttribute 不影响包含元素的 toString
- r - sjPlot - change plot line colors to black/white
- sphinx - Sphinx 按单词路径搜索
- python - 如何在方便的地方记录实例的创建、编辑、销毁?
- bash - YOCTO (MORTY) 激活 bash 完成
- vim - 突出显示文件开头和结尾的空行以及多个空行
- javascript - 如何在 HTML5 和 jquery 中使用动态数据在下拉列表中添加显示更多按钮
- java - MVC 设计 - 我可以在 Controller 类中进行域模型验证吗?
- mysql - Mysql join 2个互不相关的表
- r - persp 剂量如何定义蜱?特别是 persp 如何决定使用多少刻度和使用哪个刻度增量?