android - 如何在 Android 中缩放视图及其边界?
问题描述
我创建了一个自定义视图,并希望缩放视图及其边界。这可以通过布局实现吗?或者也许我必须在CustomView
课堂上改变一些东西?
当我在布局文件中使用scaleX
和scaleY
时,图像可以缩小或放大,但最终边界保持在原来的位置。
这是一个例子。左边是正常大小和正常比例,右边是在和轴上
的CustomView
缩放比例。0.5
x
y
如果它有帮助,它CustomView
是由少数人制作ImageView
的ConstraintLayout
。我试过只是改变layout_width
并layout_height
确定值,但只有一些视图相应地扩展,而其他视图保持大。
编辑:
这是xml
文件CustomView
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clipChildren="false"
android:clipToPadding="false"
android:padding="40dp"
tools:ignore="ContentDescription">
<ImageView
android:id="@+id/justiceTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/justiceBase"
app:layout_constraintEnd_toEndOf="@+id/justiceBase"
app:layout_constraintStart_toStartOf="@+id/justiceBase"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_justice_scale_top" />
<ImageView
android:id="@+id/justiceBase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/justiceTop"
app:srcCompat="@drawable/ic_justice_scale_base" />
<ImageView
android:id="@+id/justiceBeam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rotation="0"
app:layout_constraintBottom_toBottomOf="@+id/justiceTop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/justiceTop"
app:srcCompat="@drawable/ic_justice_scale_top_beam"
tools:ignore="ContentDescription" />
<View
android:id="@+id/leftWeightPivot"
android:layout_width="1dp"
android:layout_height="1dp"
app:layout_constraintCircle="@id/justiceBeam"
app:layout_constraintCircleAngle="260"
app:layout_constraintCircleRadius="70dp"
tools:ignore="MissingConstraints" />
<View
android:id="@+id/rightWeightPivot"
android:layout_width="1dp"
android:layout_height="1dp"
app:layout_constraintCircle="@id/justiceBeam"
app:layout_constraintCircleAngle="100"
app:layout_constraintCircleRadius="70dp"
tools:ignore="MissingConstraints" />
<ImageView
android:id="@+id/justiceWeightLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="@id/leftWeightPivot"
app:layout_constraintStart_toStartOf="@id/leftWeightPivot"
app:layout_constraintTop_toBottomOf="@id/leftWeightPivot"
app:srcCompat="@drawable/ic_justice_scale_weight" />
<ImageView
android:id="@+id/justiceWeightRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="@id/rightWeightPivot"
app:layout_constraintStart_toStartOf="@id/rightWeightPivot"
app:layout_constraintTop_toBottomOf="@id/rightWeightPivot"
app:srcCompat="@drawable/ic_justice_scale_weight" />
如果我将layout_width
and设置layout_height
为130dp
解决方案
推荐阅读
- mongodb - MongoDB:在对象中搜索
- ffmpeg - 如何在视频中应用噪音?
- amazon-web-services - 未压缩的 Redshift 集群大小
- python - Sphinx-如何自动记录位于多个文件夹中的 .py 文件?
- python - 霍夫圆中标量变量错误的索引无效
- javascript - JavaScript 可以优化这个对象吗?
- r - 在 R 中使用 gsub 根据某些模式删除一些行
- ruby-on-rails - 如何为小数制作正则表达式
- netlogo - 两个列表之间的划分并将结果存储在一个列表中 NetLogo
- android - 当我按下 DONE 时没有任何反应