放大动画图像视图
zoom in animation imageview
我正在尝试使用以下工作正常的代码来缩放图像视图
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="6000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.2"
android:toYScale="1.2"
>
</scale>
</set>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="fitXY"
tools:src="@drawable/image"
app:layout_constraintDimensionRatio="H,16:9"
app:layout_constraintTop_toTopOf="parent"/>
但它也会缩放图像视图的高度和宽度。有没有办法在不使视图变大的情况下缩放 imageview 的图像?
您可以像这样让您的图片自动调整大小以适应 imageView
<ImageView
android:id="@id/img_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"/>
adjustViewBounds
是重新缩放图像以填充 imageView 的关键
这将不起作用,因为 ImageView
本身已缩放。因此,无论 scaleType
或 adjustViewBounds
是什么,ImageView
仍会按比例缩放。图像不能与视图分开缩放,相反,您可以为 ImageView
的填充设置动画
我的建议是在另一个视图中添加 ImageView
,例如 RelativeLayout
,将 RelativeLayout
设置为您想要的大小,然后缩放 ImageView
.
执行此操作后,RelativeLayout
将保持相同大小,可用于执行您打算执行的操作,而 ImageView
会缩放。
我正在尝试使用以下工作正常的代码来缩放图像视图
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="6000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.2"
android:toYScale="1.2"
>
</scale>
</set>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="fitXY"
tools:src="@drawable/image"
app:layout_constraintDimensionRatio="H,16:9"
app:layout_constraintTop_toTopOf="parent"/>
但它也会缩放图像视图的高度和宽度。有没有办法在不使视图变大的情况下缩放 imageview 的图像?
您可以像这样让您的图片自动调整大小以适应 imageView
<ImageView
android:id="@id/img_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"/>
adjustViewBounds
是重新缩放图像以填充 imageView 的关键
这将不起作用,因为 ImageView
本身已缩放。因此,无论 scaleType
或 adjustViewBounds
是什么,ImageView
仍会按比例缩放。图像不能与视图分开缩放,相反,您可以为 ImageView
我的建议是在另一个视图中添加 ImageView
,例如 RelativeLayout
,将 RelativeLayout
设置为您想要的大小,然后缩放 ImageView
.
执行此操作后,RelativeLayout
将保持相同大小,可用于执行您打算执行的操作,而 ImageView
会缩放。