无法缩放ImageView的高度,以至于位置不变

时间:2019-04-19 15:51:16

标签: javascript java arduino

我正在尝试显示一个图像,该图像显示容器中剩余了多少液体。所以我有一个“液体”的图像,它只是一个橙色的正方形,我在这里以编程方式更改此图像的高度:

int newHeight = 802*finalPercent;
chem.getLayoutParams().height = newHeight;

它可以正确缩放,但是当图像缩放时,它会朝ImageView边界的中心移动。

该液体图像应该在静态容器图像中,因此如何缩放它,但图像底部应位于容器底部? 图片:

https://ibb.co/Cn5t40m

https://ibb.co/z5YznFq

我尝试将约束更改为轮廓,边缘和几乎所有内容。

我尝试过AdjustViewBounds,但没有效果。

我尝试了每个scaleType,但效果很小或没有效果。

<ImageView
android:id="@+id/chem"
android:layout_width="229dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:adjustViewBounds="true"
android:minWidth="572dp"
android:paddingBottom="0dp"
android:scaleType="fitXY"
android:scaleY="1"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="@+id/zero"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.193"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/zero"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="@drawable/full" />

我想缩放图像并将其保留在图像中黑色轮廓“容器”的底部,但它缩放至居中。

1 个答案:

答案 0 :(得分:0)

好的。弄清楚了。

将我的外部图像(边框图像)设置为FitEnd,将内部图像缩放为居中。将两个图像都带回图像编辑器,并切掉所有垂直额外的透明区域。将内部图像的底部约束设置为边界框图像的底部。现在可以缩放垂直,图像底部保持在所需位置。