有可能通過具有兩個ImageView
小號FrameLayout
下實現它:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/solid_blue"
android:id="@+id/img_back"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/solid_green"
android:id="@+id/img_front"/>
</FrameLayout>
而且在活動中加入onTouchListener和平移前的ImageView會做的工作:
ObjectAnimator mSlideAnim;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.curtainstyle);
final ImageView imgFront = (ImageView) findViewById(R.id.img_front);
FrameLayout parent = (FrameLayout) findViewById(R.id.parent);
parent.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
if (mSlideAnim == null) {
triggerSlideUpAnimation(imgFront);
}
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
goToAnotherPage();
break;
}
return true;
}
});
}
private void triggerSlideUpAnimation(ImageView imgFront) {
int height = imgFront.getHeight();
mSlideAnim = ObjectAnimator.ofFloat(imgFront, "translationY", 0, -height);
mSlideAnim.setDuration(300);
mSlideAnim.start();
}
private void goToAnotherPage() {
Toast.makeText(this, "Go to another page", Toast.LENGTH_SHORT).show();
}