android - 如何在 ConstraintLayout 中的 ImageVew 上放置 TextView
问题描述
我正在使用 ConstraintLayout,我想在 ImageView 上放置一个 TextView。
但我无法在 ConstraintLayout 中找到此功能。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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="match_parent"
tools:context="com.example.sayani.myApp.MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="4dp"
android:layout_marginEnd="4dp"
android:layout_marginStart="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="@drawable/image1" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="240dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="@+id/imageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"/>
</android.support.constraint.ConstraintLayout>
在上面的代码中,TextView 隐藏在 ImageView 下。
如何将文本放在图像顶部?
解决方案
如果您的应用具有 21 或更高版本的最低 SDK,您可以将其添加到您希望显示在另一个上方的任何 UI 元素中:android:elevation="4dp"
不一定是 4dp,它可以更高或更低,具体取决于您的项目中的工作原理。
推荐阅读
- javascript - 错误堆栈跟踪指向错误的行 - Node.js + Webpack
- r - 将多个图例与拼凑对齐
- wpf - 有没有办法使用 MultiBinding 更改 TextBlock 的前景?
- kubernetes - Istio + minikube + Nginx (React)。无法从浏览器或 CURL 访问
- python - 出现 Tkinter Treeview 可用空间
- math - 如何用固定大小的立方体填充相机的截锥体?
- javascript - 如何使用 Vue 刷新 Laravel cookie?
- sql - 如何将 Presto 连接到 Mongodb 容器
- angular5 - 为什么我的验证器函数用于验证未在 Angular 5 中调用的表单数组?
- unity3d - MRTK V2.2 - 空间映射自动启动