欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實現(xiàn)翻頁特效

 更新時間:2022年05月10日 14:44:53   作者:nekocode  
這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)翻頁特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android實現(xiàn)翻頁特效的具體代碼,供大家參考,具體內(nèi)容如下

android-flip是一個能夠輕松幫你實現(xiàn)水平以及豎直翻頁特效的庫,但是在判斷翻頁的時候有bug,我們需要在FlipCards.java中找到這一段:

if (Math.abs(getPageIndexFromAngle(accumulatedAngle + angleDelta) - lastPageIndex) <= 1) {
? ? ? accumulatedAngle += angleDelta;
? ? ? ? ? ?}

將它更改為:

if(((accumulatedAngle + angleDelta > lastPageIndex*180)
? ? ?&& (accumulatedAngle + angleDelta <= (lastPageIndex+1) * 180)) || ?
? ? ? ((accumulatedAngle + angleDelta < lastPageIndex*180) &&?
? ? ? ? ? ? ? ? ? ? (accumulatedAngle + angleDelta >= (lastPageIndex-1) * 180))){
? ? ? ? ? ? ? accumulatedAngle += angleDelta;
? ? ? ? ? ? }

而在翻頁的時候會有閃爍現(xiàn)象產(chǎn)生,為了減輕現(xiàn)象的發(fā)生,我們需要修改另外一個地方,在FlipViewController.java中找到這一段:

void postHideFlipAnimation() {
? ? ? if (inFlipAnimation) {
? ? ? ? handler.post(new Runnable() {
? ? ? ? ? @Override
? ? ? ? ? public void run() {
? ? ? ? ? ? hideFlipAnimation();
? ? ? ? ? }
? ? ? ? });
? ? ? }
? ? }

修改為:

void postHideFlipAnimation() {
? ? ? if (inFlipAnimation) {
? ? ? ? handler.postDelayed(new Runnable() {
? ? ? ? ? @Override
? ? ? ? ? public void run() {
? ? ? ? ? ? hideFlipAnimation();
? ? ? ? ? }
? ? ? ? }, 200);
? ? ? }
? ? }

然后我們就可以輕松地用它來為我們的app添加翻頁特效,在Activity中添加代碼:

package com.nekocode.xuedao;
?
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.aphidmobile.flip.FlipViewController;
import com.nekocode.xuedao.adapter.SubscribeIndexAdapter;
?
public class SubsecribeIndexActivity extends SherlockFragmentActivity {
?? ?private PublicData pd;
?? ?private FlipViewController mFlipView;
?? ?
?? ?@Override
?? ?public void onCreate(Bundle savedInstanceState) {
?? ??? ?super.onCreate(savedInstanceState);
?? ??? ?pd = PublicData.getInstance();
?? ??? ?
?? ??? ?mFlipView = new FlipViewController(this, FlipViewController.HORIZONTAL);
?? ??? ?mFlipView.setAdapter(new SubscribeIndexAdapter(this));
?? ??? ?
?? ??? ?setContentView(mFlipView);
?? ?}
?
?? ?@Override
?? ?protected void onResume() {
?? ??? ?super.onResume();
?? ??? ?mFlipView.onResume();
?? ?}
?
?? ?@Override
?? ?protected void onPause() {
?? ??? ?super.onPause();
?? ??? ?mFlipView.onPause();
?? ?}
}

創(chuàng)建FlipAdapter:

package com.nekocode.xuedao.adapter;
?
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
?
import com.aphidmobile.utils.UI;
import com.nekocode.xuedao.R;
?
public class SubscribeIndexAdapter extends BaseAdapter {
? private LayoutInflater inflater;
?
? public SubscribeIndexAdapter(Context context) {
? ? inflater = LayoutInflater.from(context);
? }
?
? @Override
? public int getCount() {
? ? return 5;
? }
?
? @Override
? public Object getItem(int position) {
? ? return position;
? }
?
? @Override
? public long getItemId(int position) {
? ? return position;
? }
?
? @Override
? public View getView(int position, View convertView, ViewGroup parent) {
? ? View layout = convertView;
? ? if (convertView == null) {
? ? ? layout = inflater.inflate(R.layout.item_subscribe_index, null);
? ? }
?
? ? UI
? ? ? ? .<TextView>findViewById(layout, R.id.textView7)
? ? ? ? .setText("今日熱點" + position);
?
? ? return layout;
? }
}

layout文件并沒有什么重要信息所以不放出代碼了,效果圖:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論