網站首頁 編程語言 正文
本文實例為大家分享了Android實現翻頁特效的具體代碼,供大家參考,具體內容如下
android-flip是一個能夠輕松幫你實現水平以及豎直翻頁特效的庫,但是在判斷翻頁的時候有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;
? ? ? ? ? ? }
而在翻頁的時候會有閃爍現象產生,為了減輕現象的發生,我們需要修改另外一個地方,在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();
?? ?}
}
創建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文件并沒有什么重要信息所以不放出代碼了,效果圖:
原文鏈接:https://blog.csdn.net/nekocode/article/details/18413779
相關推薦
- 2023-07-26 TypeScript中的模塊與命名空間
- 2022-11-19 Django項目中表的查詢的操作_python
- 2022-06-28 C#開發Winform實現學生管理系統_C#教程
- 2022-04-09 用C語言實現簡單的計算器功能_C 語言
- 2022-10-11 Filter過濾器和Listener監聽器
- 2022-12-15 一文搞懂C語言中的文件操作_C 語言
- 2022-07-18 Linux tar命令;sftp;創建變量;find命令;history命令;引號的使用舉例;
- 2022-09-09 python處理xml文件操作詳解_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支