开发日记——手机安全卫士 Day02 2016-7-21 完成导航页面和切换功能

来源:互联网 发布:淘宝套现信用卡手续费 编辑:程序博客网 时间:2024/06/02 13:14

手机安全卫士 Day02 2016-7-21 完成导航页面和切换功能

导航页面底端使用RadioGroup和RadioButton控件。RadioButton背景使用了自定义的背景选择器,用于控制按钮点击时显示的颜色。

背景选择器:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_checked = "true" android:drawable="@drawable/circle_blue"/>    <item android:state_checked = "false" android:drawable="@drawable/circle_gray"/></selector>

灰色圆点:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">    <solid android:color="#acacac"/></shape>

切换页面需要定义动画效果,在res目录下新建anim文件夹
(-100%p,0) (0,0) (100%p,0)
上一个页面进入动画如下:
<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"    android:fromXDelta="-100%p"    android:toXDelta="0"    android:fromYDelta="0"    android:toYDelta="0"    android:duration="500"    android:repeatCount="0"    ></translate>
由于每一个界面都需要进行滑动,定义一个父类实现手势识别功能。
public abstract class BaseSetUpActivity extends Activity {    public SharedPreferences sp;    private GestureDetector mGestureDetector;    @Override    protected void onCreate(Bundle savedInstanceState){        super.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE);        sp=getSharedPreferences("config",MODE_PRIVATE);        mGestureDetector = new GestureDetector(this,new GestureDetector.SimpleOnGestureListener(){            //e1:触碰 e2:离开            //velocity速度 pix/s            @Override            public boolean onFling(MotionEvent e1,MotionEvent e2,float velocityX,float velocityY){                if(Math.abs(velocityX)<200){                    return true;                }                if(e2.getRawX()-e1.getRawX()>200){                    //从左向右                    showLast();                    overridePendingTransition(R.anim.last_in,R.anim.next_out);                    return true;                }                if(e1.getRawX()-e2.getRawX()>200){                    //从左向右                    showNext();                    overridePendingTransition(R.anim.next_in,R.anim.last_out);                    return true;                }                return super.onFling(e1,e2,velocityX,velocityY);            }        });    }    public abstract void showLast();    public abstract void showNext();    @Override    public boolean onTouchEvent(MotionEvent event){        mGestureDetector.onTouchEvent(event);        return super.onTouchEvent(event);    }    public void startActivityAndFinishActivity(Class<?> cls){        Intent intent = new Intent(this,cls);        startActivity(intent);        finish();    }}

页面4的按钮是一个ToggleButton,按钮背景可以通过自定义图片显示器控制
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_checked="true" android:drawable="@drawable/swtch_btn_on"></item>    <item android:state_checked="false" android:drawable="@drawable/switch_btn_off"></item></selector>


0 0
原创粉丝点击