非viewFlipper滑动切换layout

内容实现如题所示功能:
1. slideExample.java

package com.example;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.Button;

public class slideExample extends Activity {

private Button aboutButton, backButton;
private ViewGroup container1, container2;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// audioMa = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
container1 = (ViewGroup) findViewById(R.id.container1);
container2 = (ViewGroup) findViewById(R.id.container2);

showWin1();
}

public void showWin1() {
aboutButton = (Button) findViewById(R.id.about_btn);
aboutButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
container1.setAnimation(AnimationUtils.loadAnimation(
slideExample.this, R.anim.push_left_out));
container2.setVisibility(View.VISIBLE);
container2.setAnimation(AnimationUtils.loadAnimation(
slideExample.this, R.anim.push_right_in));
container1.setVisibility(View.GONE);
showWin2();
}
});
}

public void showWin2() {
backButton = (Button) findViewById(R.id.back_btn);
backButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
container1.setVisibility(View.VISIBLE);
container1.setAnimation(AnimationUtils.loadAnimation(
slideExample.this, R.anim.push_left_in));
container2.setAnimation(AnimationUtils.loadAnimation(
slideExample.this, R.anim.push_right_out));
container2.setVisibility(View.GONE);
showWin1();
}
});
}
}

2.main.xml文件


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/container">

<RelativeLayout android:layout_width="fill_parent"
android:id="@+id/container1" android:layout_height="fill_parent"
android:visibility="visible">

<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="@drawable/one" />

<Button android:text="i" android:id="@+id/about_btn"
android:textColor="@drawable/red" android:layout_width="40dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" android:layout_marginRight="15dip" />

</RelativeLayout>

<RelativeLayout android:layout_width="fill_parent"
android:background="@drawable/gray" android:id="@+id/container2"
android:visibility="gone" android:layout_height="fill_parent">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="@drawable/three" />

<Button android:text="@string/back" android:id="@+id/back_btn"
android:textColor="@drawable/red" android:layout_width="40dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" android:layout_marginRight="15dip" />
</RelativeLayout>

</RelativeLayout>



3.push_left_in.xml(anim文件夹中)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-100%p" android:toXDelta="0"
android:duration="1000" />

</set>


4.push_left_out.xml(anim文件夹中)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-100%p"
android:duration="1000" />

</set>



5.push_right_in.xml(anim文件夹中)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p" android:toXDelta="0"
android:duration="1000" />
</set>

6.push_right_out.xml(anim文件夹中)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="100%p"
android:duration="1000" />
</set>


资源文件可以自己添加2张即可
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值