我尝试使用ObjectAnimator为LinearLayout内的按钮设置动画效果,当我点击布局时什么也没有发生。如何使用ObjectAnimator为LinearLayout内的按钮设置动画效果
但是,如果我更改LinearLayout中的ImageViews的按钮动画开始没有问题。
继承人是XML:
<LinearLayout
android:id="@+id/images"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/img1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1.0"
android:src="@drawable/image1"
android:visibility="visible"
/>
<ImageView
android:id="@+id/img2"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1.0"
android:src="@drawable/image2"
android:visibility="gone" />
</LinearLayout>
,这是代码:
final LinearLayout images = (LinearLayout) findViewById(R.id.images);
images.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final ObjectAnimator goneToVisible = ObjectAnimator.ofFloat(images, "rotationY", -90f, 0f);
goneToVisible.setDuration(1000);
goneToVisible.start();
}
});
寄托都工作正常,但是当我通过按钮来更改的ImageView:
<LinearLayout
android:id="@+id/images"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/img1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1.0"
android:background="@drawable/image1"
android:visibility="visible"
/>
<Button
android:id="@+id/img2"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1.0"
android:background="@drawable/image2"
android:visibility="gone" />
</LinearLayout>
final LinearLayout images = (LinearLayout) findViewById(R.id.images);
images.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//flip(image1, image2, animLength.getProgress());
final ObjectAnimator goneToVisible = ObjectAnimator.ofFloat(images, "rotationY", -90f, 0f);
goneToVisible.setDuration(1000);
goneToVisible.start();
}
});
动画不能正常工作。
如果从LinearLayout中取出按钮,它可以工作,但不在里面。我需要使用Buttons代替ImageView。
我该如何解决这个问题?
谢谢。
这将是更有益OP和未来的访问者来描述你所做的改变,以及*他们为什么工作,而不是仅仅提供代码。 – codeMagic
嗨。如果你点击按钮,它的工作正常,但如果你点击容器,它不适用于内部的按钮,但它有效,如果你有ImageVies而不是按钮。最终的LinearLayout图像=(LinearLayout)findViewById(R.id.images); images.setOnClickListener(new View.OnClickListener(){。我想单击容器以启动按钮的动画。谢谢 –
@codeMagic感谢您的评论我将更详细地解释此问题 –