sro*_*oes 6 android android-layout
我正在尝试为ImageView设置动画,以便从左到右慢慢显示.当我在解释我想要的东西之前问这个问题时,所以这次我使用HTML/JS创建了所需的效果:
在Android中获得此效果的最佳方法是什么?
我尝试更改scaleType,然后将ScaleAnimation直接应用于该ImageView:
布局:
<ImageView
android:id="@+id/graphImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:background="@android:color/transparent"
android:contentDescription="@string/stroom_grafiek"
/>
Run Code Online (Sandbox Code Playgroud)
Java的:
scale = new ScaleAnimation((float)0,
(float)1, (float)1, (float)1,
Animation.RELATIVE_TO_SELF, (float)0,
Animation.RELATIVE_TO_SELF, (float)1);
scale.setDuration(1000);
graphImage.startAnimation(scale);
Run Code Online (Sandbox Code Playgroud)
但这个stil缩放图像.
我也尝试在FrameLayout中包装ImageView,希望我能为FrameLayout设置动画:
<FrameLayout
android:layout_width="70dp"
android:layout_height="fill_parent"
android:clipChildren="true"">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left|clip_horizontal" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
这仍然会尝试扩展我的ImageView以适应FrameLayout.
有几种方法可以做到这一点 - 一种方法是简单地更改ImageView绘制图像的画布上的剪辑(即允许视图绘制的区域).缓慢增加绘制边界的右边缘将产生与示例链接中相同的效果.
我已经编写了一些示例代码来说明这种技术.如果您下载/构建/运行项目,单击图像将运行揭示动画.
看看CoveredImageView类的onDraw方法,它具有以下基本结构:
@Override
protected void onDraw(Canvas canvas) {
...
canvas.getClipBounds(mRect);
mRect.right = ...;
canvas.clipRect(mRect);
...
super.onDraw(canvas);
...
invalidate();
}
Run Code Online (Sandbox Code Playgroud)
调整剪辑,然后调用invalidate(),导致再次调用onDraw().
我还编写了一些代码来插入经过时间的正确剪辑值,这不取决于任何特定版本的Android.但是,作为一个注释,Android 3.0中有一个新的动画框架和一个ValueAnimator类可以帮助执行这些任务.
| 归档时间: |
|
| 查看次数: |
2590 次 |
| 最近记录: |