标签: objectanimator

如何设置矩阵动画以"裁剪"图像?

我正在尝试做一个图像查看器,当用户点击图像时,图像被"裁剪掉"并显示完整的图像.

例如,在下面的屏幕截图中,用户最初只能看到小狗的一部分.但是在用户点击图像后,整个小狗都被揭露了.在第一个后面褪色的图像显示了动画的结果.

截图

最初,ImageView在X和Y中缩放到50%.当用户点击图像时,ImageView将缩放回100%,并重新计算ImageView矩阵.

我尝试了各种方法来计算矩阵.但是我似乎无法找到适用于所有类型的裁剪和图像的裁剪:裁剪景观到肖像,裁剪景观到横向,裁剪纵向到纵向和裁剪纵向到横向.这甚至可能吗?

这是我现在的代码.我正试着找些什么setImageCrop().

public class MainActivity extends Activity {

private ImageView img;
private float translateCropX;
private float translateCropY;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    img = (ImageView) findViewById(R.id.img);
    Drawable drawable = img.getDrawable();

    translateCropX = -drawable.getIntrinsicWidth() / 2F;
    translateCropY = -drawable.getIntrinsicHeight() / 2F;

    img.setScaleX(0.5F);
    img.setScaleY(0.5F);
    img.setScaleType(ScaleType.MATRIX);

    Matrix matrix = new Matrix();
    matrix.postScale(2F, 2F); //zoom in 2X
    matrix.postTranslate(translateCropX, translateCropY); //translate to the center of the image
    img.setImageMatrix(matrix);

    img.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) { …
Run Code Online (Sandbox Code Playgroud)

graphics android transformation matrix objectanimator

8
推荐指数
2
解决办法
5351
查看次数

如何使用ObjectAnimator删除动画的慢速结束?

我有这个ObjectAnimator:

    cloudAnim2 = ObjectAnimator.ofFloat(cloud2ImageView, "x",500, 1000);
    cloudAnim2.setDuration(3000);
    cloudAnim2.setRepeatCount(ValueAnimator.INFINITE);
    cloudAnim2.setRepeatMode(ValueAnimator.RESTART);        
    cloudAnim2.start();
    cloudAnim2.addListener(new AnimatorListener() {
        @Override
        public void onAnimationCancel(Animator animation) {}
        @Override
        public void onAnimationEnd(Animator animation) {}
        @Override
        public void onAnimationRepeat(Animator animation) {}
        @Override
        public void onAnimationStart(Animator animation) {}
    });
Run Code Online (Sandbox Code Playgroud)

如您所见,云将从位置500开始并将动画到位置1000,然后它将重复动画.

问题是动画越来越慢,因为它接近完成.我的意思是,运动的速度并不总是一样的.

我希望速度变得总是一样的.如何才能做到这一点?

谢谢

animation android android-animation android-view objectanimator

7
推荐指数
1
解决办法
2330
查看次数

动画启动时可以更改ObjectAnimator结束值吗?

我有一个对象动画师启动,我想有时在动画启动时更改结束值,但没有停止并重新启动它.

怎么能实现这一目标?我在谷歌找不到任何信息.

样品:

XMovement = ObjectAnimator.ofFloat(view, "x", startX, endX);                
XMovement.setDuration(ANIMATION_TIME);
XMovement.start();
Run Code Online (Sandbox Code Playgroud)

我想endX在动画启动时实时更改值.

谢谢

android android-animation android-view objectanimator

7
推荐指数
0
解决办法
735
查看次数

尝试调用接口方法'void android.support.v7.widget.DecorContentParent.setWindowCallback(android.view.Window $ Callback)'

这是我的项目:

项目

animated_pa​​th.xml:

<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
                 xmlns:tools="http://schemas.android.com/tools"
                 android:drawable="@drawable/triangle"
                 tools:targetApi="21">
    <target
        android:name="t"
        android:animation="@animator/path"/>
</animated-vector>
Run Code Online (Sandbox Code Playgroud)

path.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
        android:duration="3000"
        android:propertyName="pathData"
        android:repeatCount="infinite"
        android:repeatMode="reverse"
        android:valueFrom="M 100 100 L 300 100 L 300 300 L 100 300z"
        android:valueTo="M 100 100 L 300 100 L 200 300 L 200 300z"
        android:valueType="pathType"/>
</set>
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml中:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.kycq.reader">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".LoadingActivity"
            android:theme="@style/ActivityTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity"
            android:theme="@style/ActivityTheme">
        </activity>
    </application>

</manifest> …
Run Code Online (Sandbox Code Playgroud)

android nullpointerexception objectanimator

7
推荐指数
2
解决办法
3531
查看次数

为Android应用程序创建3D动画

嘿家伙我需要根据屏幕上用户滑动的速度创建3D翻转/旋转动画,我能够使用ObjectAnimator及其相关属性创建此动画,但我需要建议如何在android中创建3D动画以上.我还需要执行一些部分旋转的动画

虽然对于android我们可以使用OPENGL但是对于一个简单的动画OPENGL太重了,因为我们没有设计真正的游戏我已经引用了以下链接

https://2cupsoftech.wordpress.com/2012/09/18/3d-flip-between-two-view-or-viewgroup-on-android/

http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html

3d animation android objectanimator animatorset

7
推荐指数
1
解决办法
242
查看次数

缩放视图到父版面大小

我试图通过使用对象动画师将视图缩放到布局大小.这是一个观点LinearLayout.视图确实拉伸,但直到两个方向(即X和Y)的屏幕尺寸.

这是代码.

我觉得问题是这个:

  1. 计算必须完成多少缩放的公式.

    zoomTillX = screen_width/zoomView_width;
    zoomTillY = screen_height/zoomView_height;
    
    Run Code Online (Sandbox Code Playgroud)
  2. 或者使用以错误方式完成的Animation属性代码.

请让我知道如何实现放大.

public class MainActivity extends AppCompatActivity {

    TextView tv;
    double screen_height;
    LinearLayout zoomView;
    double screen_width;
    double zoomTillX;
    double zoomTillY;
    double zoomView_width;
    double zoomView_height;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        tv = (TextView) findViewById(R.id.tv);
        zoomView = (LinearLayout) findViewById(R.id.zoomView);
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        screen_height = (double)dm.heightPixels;
        screen_width = (double)dm.widthPixels;
        zoomView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                zoomView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                zoomView_width = (double)zoomView.getMeasuredWidth();
                zoomView_height =  (double)zoomView.getMeasuredHeight();


            } …
Run Code Online (Sandbox Code Playgroud)

android android-animation objectanimator

7
推荐指数
1
解决办法
2065
查看次数

在Android动画矢量中以编程方式设置动画值从值

我创建了一个动画矢量,如下所示,它用于实现从path1到path2的曲线变形动画.我有其他曲线路径,如path3,path4,path5,我需要实现路径1 - > path3,path1-> path4,path2-> path1,path2-> path3 ...的变形动画,有很多组合,因此,我需要设置"android:valueFrom"和"android:valueTo"程序化的盟友,否则,我必须手动创建大量这样的动画矢量文件.我没有在Android动画包中找到任何API.我能做些什么?还有其他解决方案吗?

<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt"
    android:drawable="@drawable/equalizer_gradient0" >
    <target android:name="v">
        <aapt:attr name="android:animation">
            <objectAnimator
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:duration="500"
                android:propertyName="pathData"
                android:valueFrom="@string/path1"
                android:valueTo="@string/path2"
                android:valueType="pathType"/>
        </aapt:attr>
    </target>
</animated-vector>
Run Code Online (Sandbox Code Playgroud)

animation android vector objectanimator

7
推荐指数
0
解决办法
168
查看次数

确定ObjectAnimator的translationX/Y值; 如何将视图移动到精确的屏幕位置?

我正在尝试使用ObjectAnimator.ofFloat(...)将视图移动到屏幕的右上角但是,我没有得到我期望的结果.我预先使用ViewTreeListener等获取视图的坐标,我已经知道我需要从整个宽度的末尾偏移的x值.我无法将任何一个维度移动到我想要的位置.相关代码:

获得起始坐标; 目前的观点是:

int[] userCoords = new int[]{0,0};
userControlLayout.getLocationInWindow(userCoords);
//also tried getLocationInScreen(userCoords); same result
userUpLeft = userCoords[0];
userUpTop = userCoords[1];
Run Code Online (Sandbox Code Playgroud)

令人惊讶的是,当我打电话时,我得到与userUpLeft相同的值(在屏幕坐标中,而不是相对于父节点)userControlLayout.getLeft()我希望它们根据我对文档的理解而有所不同.无论如何...

构造ObjectAnimators:

//testXTranslate is a magic number of 390 that works; arrived at by trial. no idea why that 
// value puts the view where I want it; can't find any correlation between the dimension 
// and measurements I've got
ObjectAnimator translateX = ObjectAnimator.ofFloat(userControlLayout, "translationX",
                                                                  testXTranslate);

//again, using another magic number of -410f puts me at the Y …
Run Code Online (Sandbox Code Playgroud)

android android-layout objectanimator

6
推荐指数
1
解决办法
3万
查看次数

没有xml的动画片段

我正在寻找一种方法来在不使用 xml 的情况下为片段的过渡设置动画。

动画片段的典型方法是将 xml 动画器与片段一起传递给FragmentTransaction.setCustomAnimations(例如,请参见/sf/answers/345531161/

相反,我想发送setCustomAnimations一个ObjectAnimator应用于片段,但遗憾的是这不是一个选项。

关于如何实现这一点的任何想法?

xml animation android android-fragments objectanimator

6
推荐指数
1
解决办法
666
查看次数

Android ObjectAnimator与ViewPropertyAnimator

ObjectAnimator和ViewPropertyAnimator改变属性值有什么区别?

ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(myObject, "X", 0.0f, 100.0f);
Run Code Online (Sandbox Code Playgroud)

我正在尝试myObject.getX()上面objectAnimator正在进行中,并且我在0.0f到100.0之间获得了一个在路上的值.

myObject.setX(0.0f);
myObject.animate().x(100.0f);
Run Code Online (Sandbox Code Playgroud)

但是,我得到了精确的100.0当我myObject.getX()倒是而上述ViewPropertyAnimator工作正在进行中.

我无法弄清楚是什么造成了这种差异.

提前致谢.

java android objectanimator animator viewpropertyanimator

6
推荐指数
1
解决办法
2343
查看次数