Android View 动画问题

问题如下:
FrameLayout中现有2个对象View1,View2,现在想让View1作为主界面,View2作为弹出面板。
在点击view1时,view2从底部缓慢滑出,逐渐覆盖view1。
现在问题是滑出已实现,头疼的是,view2从底部滑出时,view1不是被逐渐覆盖,而是view1直接变黑背景,view2滑出。
请问如何能让view2从底部缓慢滑出时,逐渐覆盖view1,而不view1直接变黑。

 

我的代码如下:
package com.cloud;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.OvershootInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;

public class AnimateTestActivity extends Activity implements
                AdapterView.OnItemClickListener, View.OnClickListener {
        private ListView mPhotosList;
        private ViewGroup mContainer;
        private ImageView mImageView;

        // Names of the photos we show in the list
        private static final String[] PHOTOS_NAMES = new String[] { "Lyon",
                        "Livermore", "Tahoe Pier", "Lake Tahoe", "Grand Canyon", "Bodie" };

        // Resource identifiers for the photos we want to display

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

                setContentView(R.layout.main);

                mPhotosList = (ListView) findViewById(R.id.list);
                mImageView = (ImageView) findViewById(R.id.picture);
                mContainer = (ViewGroup) findViewById(R.id.container);

                // // Prepare the ListView
                final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                                android.R.layout.simple_list_item_1, PHOTOS_NAMES);

                mPhotosList.setAdapter(adapter);
                mPhotosList.setOnItemClickListener(this);

                // Prepare the ImageView
                mImageView.setBackgroundColor(0x00ff0000);
                mImageView.setClickable(true);
                mImageView.setFocusable(true);
                mImageView.setOnClickListener(this);

                // Since we are caching large views, we want to keep their cache
                // between each animation
                mContainer
                                .setPersistentDrawingCache(ViewGroup.PERSISTENT_ANIMATION_CACHE);
        }



        public void onClick(View v) {
                TranslateAnimation rotation;
                rotation = new TranslateAnimation(0f, 0f, 0f, 800f);

                rotation.setDuration(500);
                rotation.setFillAfter(false);
                rotation.setInterpolator(new AccelerateInterpolator());
                rotation.setAnimationListener(new ViewHidden());
                mContainer.startAnimation(rotation);
        }

        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                // TODO Auto-generated method stub
                TranslateAnimation rotation;

                mPhotosList.setVisibility(View.GONE);
                mImageView.setVisibility(View.VISIBLE);
                mImageView.requestFocus();

                rotation = new TranslateAnimation(0f, 0f, 800f, 0f);

                rotation.setDuration(500);
                rotation.setFillAfter(false);
                rotation.setInterpolator(new OvershootInterpolator());

                mContainer.startAnimation(rotation);

        }
       
        private final class ViewHidden implements Animation.AnimationListener {

        public ViewHidden() {
        }

        public void onAnimationStart(Animation animation) {
        }

        public void onAnimationEnd(Animation animation) {
                mPhotosList.setVisibility(View.VISIBLE);
                    mImageView.setVisibility(View.GONE);
                    mPhotosList.requestFocus();
        }

        public void onAnimationRepeat(Animation animation) {
        }
    }

}

界面xml如下:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/container" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layoutAnimation="@anim/layout_bottom_to_top_slide">

        <ListView android:id="@+id/list"
                android:persistentDrawingCache="animation|scrolling"
                android:layout_width="fill_parent" android:layout_height="fill_parent"
                android:layoutAnimation="@anim/layout_bottom_to_top_slide" />

        <ImageView android:id="@+id/picture" android:scaleType="fitCenter"
                android:layout_width="fill_parent" android:layout_height="fill_parent"
                android:src="@drawable/photo2" android:visibility="gone" />
</FrameLayout>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值