它奇怪而奇怪,但似乎当我将AnimatorListener附加到我用于动画片段事务的ObjectAnimator时,回调实际上在动画结束前稍微调用.我使用监听器将内容填充到片段中(来自DB).这个操作有时需要很长时间(~200ms),当我在onCreate左右时,它只会破坏动画,因为在动画过程中会返回并呈现内容......然后会有很多垃圾和口吃.因此,当我将填充调用添加到监听器时,它也适用于DB选择需要很长时间.但有时它几乎是瞬间的,在这种情况下,当动画结束前调用回调时我遇到了问题.回调和实际结束之间的差距很长,从DB返回数据并再次破坏动画的流动性:/
你们知道吗,如何解决这个问题?下面几乎是片段的完整代码.
所以基本上有两种方法可以解决这个问题.我可以找到完全另一种解决方案,如何在没有垃圾动画的情况下将内容填充到片段,或者我可以找到一种方法来解决监听器的问题.
还有一种我不喜欢的方式.我可以创建一个Handler并调用postDelayed..awful解决方案:)
public class ImportantContactsFragment extends Fragment {
public static final String TAG = ImportantContactsFragment.class.getSimpleName();
private ListView list;
private Spinner departmentsSwitcher;
private Spinner facultiesSwitcher;
private ContactsAdapter adapter;
private ArrayList<ImportantContact> currentListOfPeople;
private int currentFaculty = 1;
private Department currentDeparment = Department.STUDY_DEPARTMENT;
private PullToRefreshAttacher mPullToRefreshAttacher;
private boolean boot = true;
private AsyncTask<Integer, ArrayList<ImportantContact>, ArrayList<ImportantContact>> task;
private ArrayList<Faculty> faculties;
private SpinnerAdapter departmentsSpinnerAdapter;
private SpinnerAdapter facultiesSpinnerAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
currentListOfPeople = new ArrayList<ImportantContact>();
faculties = …Run Code Online (Sandbox Code Playgroud) animation android android-asynctask android-fragments objectanimator
我一直试图动画两个片段之间的过渡.我最初在xml中放置了一个属性动画(并没有真正起作用),然后将其更改为objectAnimator.由于某些原因,Android Studio无法识别objectAnimator标记.
这是我的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nick.randomapplication" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Base.AppCompat.Light" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
我的build.Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.nick.randomapplication"
minSdkVersion 19
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:20.0.+"
}
Run Code Online (Sandbox Code Playgroud)
和xml文件:
<?xml version="1.0" encoding="utf-8"?> …Run Code Online (Sandbox Code Playgroud) 官方缩放视图教程使用a AnimatorSet来放大View.随着视野的扩大,它会产生向下运动的错觉.之后,AnimatorSet只是向后重放以创建缩小的幻觉.
我需要实现的是与此完全相反的.我需要从扩展视图开始,然后将其缩小为一个向上移动的较小视图:
我似乎不能在示例中使用反转代码.该示例假定您首先放大视图并展开它,然后将其缩小回原始缩略图图标.
这是我到目前为止所尝试的内容.我的XML布局是
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#1999da">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center">
<!-- The final shrunk image -->
<ImageView
android:id="@+id/thumb_button_1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginRight="1dp"
android:visibility="invisible"/>
</LinearLayout>
</LinearLayout>
<!-- The initial expanded image that needs to be shrunk -->
<ImageView
android:id="@+id/expanded_image"
android:layout_width="wrap_content"
android:layout_height="125dp"
android:layout_gravity="center"
android:src="@drawable/title_logo_expanded"
android:scaleType="centerCrop"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
这是执行缩小操作的方法.我基本上试图颠倒教程中的过程:
private void zoomImageFromThumbReverse(final View expandedImageView, int imageResId, final int duration) {
// If there's an animation in …Run Code Online (Sandbox Code Playgroud) java android android-animation objectanimator viewpropertyanimator
<objectAnimator
android:propertyName="string"
android:duration="int"
android:valueFrom="float | int | color"
android:valueTo="float | int | color"
android:startOffset="int"
android:repeatCount="int"
android:repeatMode=["repeat" | "reverse"]
android:valueType=["intType" | "floatType"]/>
Run Code Online (Sandbox Code Playgroud)
好的我正在学习android中的一些动画.我从谷歌开发者文档中得到了两个实际上我无法理解的属性
android:propertyName="string"
android:valueType=["intType" | "floatType"]
Run Code Online (Sandbox Code Playgroud)
一些价值观是有道理的,"fade", "rotation", "alpha"
但其他人喜欢什么endYear, firstDayOfWeek
我没有找到关于这些的详细文档,或者我可能无法理解各种教程和Google Docs试图传达的内容.
**
我怀疑是从哪里可以获得所有可能的值
"propertyName"而且"valueType"我的意思是它实际上它实际上是如何影响动画的
**
我正在按照本教程进行操作,并尝试使用属性以便更好地理解.
比如下面附上的截图显示了这么多的可能性,propertyName但我不知道它们是如何理解的.

更多Over propertyName接受"x"和"y"作为值,但它们不会进入窗口.
在的情况下,ValueType如果我改变"floatType"到"intType"在教程的下文提到片断轮
<objectAnimator
android:duration="3000"
android:propertyName="rotation"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:valueTo="180"
android:valueType="floatType" />
Run Code Online (Sandbox Code Playgroud)
它停止动画.. ??????
可以任何人解释这个问题或来源,以便我可以弄清楚..
这是Google文档中解释的内容
注意: - 我第一次尝试动画,不仅是Android,还有我的生活......
我有一个具有无限重复模式的对象动画师.我想在它第一次启动时加速它...而不是每次它都重复它
怎么能实现这一目标?
我的代码:
universeMovement1 = ObjectAnimator.ofFloat(universeImageView, "x", 0, sw);
universeMovement1.setDuration(UNIVERSE_MOVEMENT_TIME);
universeMovement1.setRepeatCount(ObjectAnimator.INFINITE);
universeMovement1.setRepeatMode(ObjectAnimator.RESTART);
universeMovement1.setInterpolator(new AccelerateInterpolator());
Run Code Online (Sandbox Code Playgroud) animation android interpolation android-animation objectanimator
我意识到objectanimator对象的暂停和恢复方法仅适用于API:19.但是,既然我,也没有一半的Android用户都有这个API,有没有办法让你的动画暂停,然后从同一状态恢复,而不是从头开始?任何帮助将不胜感激.
我想使用scaleX和scaleY振动视图,我正在使用此代码进行操作,但问题是有时视图未正确重置,并且显示应用了比例...
我希望在动画结束时,必须始终以原始状态查看视图
这是代码:
ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.9f);
scaleX.setDuration(50);
scaleX.setRepeatCount(5);
scaleX.setRepeatMode(Animation.REVERSE);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.9f);
scaleY.setDuration(50);
scaleY.setRepeatCount(5);
scaleY.setRepeatMode(Animation.REVERSE);
set.play(scaleX).with(scaleY);
set.start();
Run Code Online (Sandbox Code Playgroud)
谢谢
我有一个DialogFragment,我show()当用户点击我的应用程序的按钮.
我想设置一个动画,以便DialogFragment在它启动时进行Z-axix旋转(即3d卡翻转动画).
当显示时,我成功地使用了windowAnimationStyle以下样式来执行简单的动画(使用View Animation框架)DialogFragment:
<style name="windowAnimationCardFlip" parent="@android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">@anim/card_flip_left_in</item>
<item name="android:windowExitAnimation">@anim/card_flip_left_out</item>
</style>
Run Code Online (Sandbox Code Playgroud)
问题是View Animation框架(据我所知)非常有限,而且我能做的唯一旋转(至少在xml上)是2D XY旋转(我想要一个"3D" "z轴旋转).
我尝试使用Property Animation框架(特别是一个用XML编写的Object Animator),但是,虽然我能够在加载简单时实现效果,Fragments如官方android教程中所述,当我尝试将该XML ObjectAnimator应用于windowEnterAnimation属性,没有任何反应.
那么,我想知道会发生什么?是否可以使用ObjectAnimator为windowEntry事件设置动画?如果没有,还有其他解决方案吗?
我知道API级别19支持ObjectAnimators上的pause()和resume().但是在API级别14的项目中,我有一个ObjectAnimator应用于Image视图来旋转它.我想在触摸时暂停ObjectAnimator提供的动画,并从图像视图所在的位置(触摸前)恢复它.
所以我试图保存当前的播放时间并取消我的stopAnimation()函数上的对象动画.
private void stopAnimation(){
currentTime = mGlobeAnimator.getCurrentPlayTime();
mGlobeAnimator.cancel();
}
Run Code Online (Sandbox Code Playgroud)
在startAnimation()函数中,我重新创建动画师,将其目标设置为图像视图,设置保存的播放时间并启动它.
private void startAnimation(Context context, View view, float startAngle) {
ObjectAnimator globeAnimatorClone = (ObjectAnimator)AnimatorInflater.loadAnimator(context, R.animator.rotate_globe);
globeAnimatorClone.setTarget(mImageView);
globeAnimatorClone.setCurrentPlayTime(currentTime);
globeAnimatorClone.start();
}
Run Code Online (Sandbox Code Playgroud)
这不起作用.在19岁之前,有任何人会帮忙请求暂停和恢复动画师为API级别提供的动画吗?
我正在尝试做一个图像查看器,当用户点击图像时,图像被"裁剪掉"并显示完整的图像.
例如,在下面的屏幕截图中,用户最初只能看到小狗的一部分.但是在用户点击图像后,整个小狗都被揭露了.在第一个后面褪色的图像显示了动画的结果.

最初,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) android ×10
objectanimator ×10
animation ×5
android-view ×1
api ×1
graphics ×1
java ×1
matrix ×1
xml ×1