android - 如何在约束布局中将视图放置到与另一个视图的特定偏移量
问题描述
所以,我有两张图片。一个(小)图像必须位于第二个图像(较小)的底部轴的中间,但应稍微偏离 Y 轴。我试图在约束布局中做到这一点。我知道将较小图像的顶部和底部约束设置为较大图像的底部。如何在约束布局中实现这一点? 编辑 1 我怎样才能将上述链接中的美女与野兽照片稍微向下移动到 Y 轴
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="@+id/singapore"
android:scaleType="centerCrop"
android:layout_width="240dp"
android:layout_height="240dp"
android:src="@drawable/singapore"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</ImageView>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/poster"
app:layout_constraintBottom_toBottomOf="@id/singapore"
app:layout_constraintEnd_toEndOf="@id/singapore"
app:layout_constraintStart_toStartOf="@+id/singapore"
app:layout_constraintTop_toBottomOf="@id/singapore">
</ImageView>
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
将较小图像的顶部和底部设置为较大图像的底部,将较小的图像垂直居中于较大图像的底部边缘。您现在可以10dp
通过指定较小图像的平移来将较小的图像向下移动:
android:translationY="10dp"
请参阅查看文档中对 y 转换属性的描述。
推荐阅读
- angular - 在土星材料日期范围选择器中显示日期值
- sql - SELECT * FROM 之间的差异
- python - “运行时未实现的依赖关系”:创建动态依赖关系时出错
- javascript - 如何发送 VueJS 对象以存储在 Laravel 控制器中?
- reactjs - Logout error with conditional collection on React Firebase app
- python - 更新变量并更改导入模块
- python - 无法使用scrapy提取数据
- python-3.x - 如何编写具有多种数据类型python的矩阵?
- reactjs - 运行生产构建时找不到页面在重新加载时反应 js
- c# - 序列化为没有属性名的 json