У меня довольно сложный макет. Я использую относительный макет в качестве корня, а затем внутри него у меня есть несколько табличных представлений и некоторое дальнейшее вложение. Когда я анимирую изображение между этими макетами, мои изображения обрезаются. У меня есть фон на родительском макете, и анимация выглядит так, как будто он идет под ним. Я установил android: clipChildren = "false" и android: clipToPadding = "false" на всех макетах. Я также установил anim.setZAdjustment (Animation.ZORDER_TOP); на всех моих анимациях. Что я делаю не так?
РЕДАКТИРОВАТЬ: я нашел по крайней мере 2 ошибки до сих пор. android: background = с шестнадцатеричным цветом вызывает серьезные проблемы с анимацией. В раскладках таблиц также есть regoin, что вызывает отсечение. Я также вижу то же самое с разметкой кадров. Я добавлю ответ, как только получу, что все работает так, как я хочу. Я чувствую, что использование только линейных макетов является решением.
Вот пример кода, который вызывает проблему. Если вы удалите два дочерних относительных макета, анимация завершится, как и ожидалось.
Java:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView imageViewtop = (ImageView) findViewById(R.id.ImageView01);
imageViewtop.setOnClickListener(btnCardListener);
}
private OnClickListener btnCardListener = new OnClickListener() {
public void onClick(View v) {
ImageView ImageView03 = (ImageView) findViewById(R.id.ImageView03);
ImageView ImageView05 = (ImageView) findViewById(R.id.ImageView05);
int[] playLoc = { 0, 0 };
int[] botLoc = { 0, 0 };
ImageView05.getLocationOnScreen(playLoc);
ImageView03.getLocationOnScreen(botLoc);
int xMove = playLoc[0] - botLoc[0];
int yMove = playLoc[1] - botLoc[1];
AnimationSet animSet = new AnimationSet(true);
RotateAnimation ranim = new RotateAnimation(0f, 180f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f); // , 200, 200); //
// canvas.getWidth()
// 2, canvas.getHeight() / 2);
ranim.setDuration(400);
ranim.setInterpolator(new DecelerateInterpolator());
TranslateAnimation transAnim = new TranslateAnimation(
Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, xMove, // +80.0f,
Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, yMove // -100.0f
);
transAnim.setInterpolator(new DecelerateInterpolator()); // AccelerateInterpolator
// ,
// LinearInterpolator
transAnim.setZAdjustment(Animation.ZORDER_TOP);
transAnim.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) {
}
public void onAnimationEnd(Animation animation) {
ImageView ImageView03 = (ImageView) findViewById(R.id.ImageView03);
ImageView ImageView05 = (ImageView) findViewById(R.id.ImageView05);
ImageView05.setVisibility(View.VISIBLE);
ImageView03.setVisibility(View.INVISIBLE);
}
public void onAnimationRepeat(Animation animation) {
}
});
transAnim.setDuration(1000);
// Order matters...
animSet.addAnimation(ranim);
animSet.addAnimation(transAnim);
ImageView03.startAnimation(animSet);
}
};
XML:
<RelativeLayout android:id="@+id/relativeParentLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:clipToPadding="false">
<RelativeLayout android:id="@+id/relativeParentLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="150dip" android:background="#440000"
android:layout_alignParentTop="true" android:clipChildren="false"
android:clipToPadding="false">
<ImageView android:layout_height="wrap_content" android:id="@+id/ImageView01"
android:layout_width="wrap_content" android:src="@drawable/card_back"
android:layout_weight="0" android:layout_alignParentTop="true" />
<ImageView android:layout_height="wrap_content" android:id="@+id/ImageView03"
android:layout_width="wrap_content" android:src="@drawable/card_back"
android:layout_weight="0" android:layout_gravity="center_vertical"
android:layout_alignParentRight="true" />
</RelativeLayout>
<RelativeLayout android:id="@+id/relativeParentLayout2"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="150dip" android:background="#000044"
android:layout_alignParentBottom="true" android:clipChildren="false"
android:clipToPadding="false">
<ImageView android:layout_height="wrap_content"
android:layout_below="@+id/LinearLayout01" android:id="@+id/ImageView05"
android:layout_width="wrap_content" android:src="@drawable/card_back"
android:layout_weight="0" android:layout_alignParentBottom="true" />
</RelativeLayout>
</RelativeLayout>