问题如下:
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>