3D缩水过滤工具 手机版

来源:互联网 发布:2016免费刷q币软件 编辑:程序博客网 时间:2024/04/16 15:45

360手机助手,应用宝等应用市场搜索“3D过滤器”可以下载。

下面来点干货,同一页面不使用viewpager自动渐变轮换。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_unlock" >


    <!-- 第一页 -->


    <LinearLayout
        android:id="@+id/one_bg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg_unlock"
        android:orientation="vertical" >
    </LinearLayout>
    <!-- 第二页 -->


    <LinearLayout
        android:id="@+id/two_bg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/guide_two_bg"
        android:orientation="vertical" >
    </LinearLayout>
 

    <!-- 第一页 -->


    <RelativeLayout
        android:id="@+id/guide_one"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="100dp"
        android:gravity="center" >


        <View
            android:id="@+id/icon"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_centerHorizontal="true"
            android:background="@drawable/ic_launcher" />


        <TextView
            android:id="@+id/app_name"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_below="@id/icon"
            android:layout_marginTop="30dp"
            android:gravity="center"
            android:text="@string/app_name"
            android:textColor="#ffffff"
            android:textSize="25sp" />


        <TextView
            android:id="@+id/version"
            android:layout_width="fill_parent"
            android:layout_height="20dp"
            android:layout_below="@id/app_name"
            android:gravity="center"
            android:text="第一页"
            android:textColor="#ffffff"
            android:textSize="15sp" />


        <View
            android:id="@+id/wearcare"
            android:layout_width="170.64dp"
            android:layout_height="43.92dp"
            android:layout_below="@id/version"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10dp"
            android:background="@drawable/wearcare" />
    </RelativeLayout>


    <!-- 第二页 -->


    <RelativeLayout
        android:id="@+id/guide_two"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="100dp"
        android:gravity="center" >


        <View
            android:id="@+id/icon1"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_centerHorizontal="true"
            android:background="@drawable/bbt" />


        <TextView
            android:id="@+id/app_name1"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_below="@id/icon1"
            android:layout_marginTop="30dp"
            android:gravity="center"
            android:text="第二页"
            android:textColor="#ffffff"
            android:textSize="25sp" />
    </RelativeLayout>
  

</FrameLayout>

请看代码,主要是使用层次布局FrameLayout,demo只写了两个层次的轮换


接下来上代码部分。

首先是动画控制代码


out_righttoleft_dao.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >


    <!-- 定义从右向左滑动时,当前页出去的动画 -->
    <translate
        android:duration="1000"
        android:fromXDelta="0"
        android:toXDelta="-100%" />


</set>



in_righttoleft_dao.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >


    <!-- 定义从右向左滑动时,后一页进入的动画 -->
    <translate
        android:duration="1000"
        android:fromXDelta="100%"
        android:toXDelta="0" />


</set>



然后是activity部分代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityStack.popAllActivityExceptOne(null);
// ActivityStack.popActivity(this);
setContentView(R.layout.activity_guide);
init();
initHandler();
initView();
loadView();
}


protected void init() {
activity = this;
mTimer = new Timer();
mBackground = new LinearLayout[2];
mGuideLayouts = new RelativeLayout[2];
out = AnimationUtils.loadAnimation(this, R.anim.out_righttoleft_dao);
in = AnimationUtils.loadAnimation(this, R.anim.in_righttoleft_dao);
}


protected void initHandler() {
super.initHandler();
handler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
mGuideLayouts[mNowPostion1].startAnimation(out);
mGuideLayouts[mNowPostion2].startAnimation(in);
mGuideLayouts[mNowPostion1].setVisibility(View.GONE);
mGuideLayouts[mNowPostion2].setVisibility(View.VISIBLE);
postion++;
loadView();
break;
case 1:
crossfade(postion);
break;
default:
break;
}
}
};
}


protected void initView() {
int[] bg = new int[] { R.id.one_bg, R.id.two_bg};
int[] guide = new int[] { R.id.guide_one, R.id.guide_two };
for (int i = 0; i < 2; i++) {
mBackground[i] = (LinearLayout) findViewById(bg[i]);
mGuideLayouts[i] = (RelativeLayout) findViewById(guide[i]);
if (i != 0) {
mBackground[i].setVisibility(View.GONE);
mGuideLayouts[i].setVisibility(View.GONE);
}
}

}


@SuppressLint("NewApi")
private void crossfade(final int postion) {
mNowPostion1 = postion % 2;
if (mNowPostion1 == 1) {
mNowPostion2 = 0;
} else {
mNowPostion2 = mNowPostion1 + 1;
}
mBackground[mNowPostion2].setAlpha(0f);
mBackground[mNowPostion2].setVisibility(View.VISIBLE);
mBackground[mNowPostion2].animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);
mBackground[mNowPostion1].animate().alpha(0f).setDuration(mShortAnimationDuration)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mBackground[mNowPostion1].setVisibility(View.GONE);
}


public void onAnimationStart(Animator animation) {
sendMsg(0, null);
}
});
}


protected void loadView() {
// 休眠5秒。
if (task != null) {
task = null;
}
task = new TimerTask() {
public void run() {
sendMsg(1, null);
}
};
mTimer.schedule(task, TimeInterval);
}

最后当然就是效果图了

不过由于项目问题,所以图片p了一下,各位凑合看一下效果。


0 0
原创粉丝点击