首页 文章 精选 留言 我的

精选列表

搜索[android wear],共10000篇文章
优秀的个人博客,低调大师

Android安卓比较完美的无限自动轮播

轮播功能在APP中是比较常见的,网上也有很多第三方的自动轮播库,做的很不错,这里自己手写一版简单的ViewPager+Handler机制的自动无限轮播,小白可以直接上手的。 先上简单的核心代码,代码中有详细的注释。 private void initView() { auto_viewpager = (ViewPager) findViewById(R.id.vp_shuffling); tv_content = (TextView) findViewById(R.id.tv_content); dotLayout = (LinearLayout) findViewById(R.id.layout_point); mADParseArray = new ArrayList<String>(); mADParseArray .add("http://m.easyto.com/m/zhulifuwu_banner.jpg"); mADParseArray .add("http://m.easyto.com/m/japan/images/banner_3y_new.jpg"); mADParseArray .add("http://m.easyto.com/m/japan/images/banner_5y_new.jpg"); final int size = mADParseArray.size(); content = new String[]{"轮播图介绍一", "轮播图介绍二", "轮播图介绍三"}; auto_viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { /** * @param position:跳转完毕的页码角标,这个方法做自动轮播 */ @Override public void onPageSelected(int position) { Log.e(TAG, "onPageSelected"); refreshPoint(position % size); if (mHandler.hasMessages(HOME_AD_RESULT)) { mHandler.removeMessages(HOME_AD_RESULT); } mHandler.sendEmptyMessageDelayed(HOME_AD_RESULT, 3000); } /** * @param arg0:滑动时代表当前页角标,滑动结束时代表滑动停止时的页码角标 * @param arg1:0-1或者1-0变化 * @param arg2:0 <-> 屏幕的宽度值变化 */ @Override public void onPageScrolled(int arg0, float arg1, int arg2) { Log.e(TAG, "onPageScrolled"); } /** * @param arg0:0 没滑动 1:正在滑动 2:滑动完毕 */ @Override public void onPageScrollStateChanged(int arg0) { Log.e(TAG, "onPageScrollStateChanged = " + arg0); if (ViewPager.SCROLL_STATE_DRAGGING == arg0 && mHandler.hasMessages(HOME_AD_RESULT)) { mHandler.removeMessages(HOME_AD_RESULT); } } }); // BannerAdapter adapter = new BannerAdapter(mContext, mADParseArray); auto_viewpager.setAdapter(adapter); initPointsLayout(size); auto_viewpager.setCurrentItem(size * 1000, false);//设置当前position,不设置开始无法右滑 // 利用handler启动自动轮播 mHandler.sendEmptyMessageDelayed(HOME_AD_RESULT, 3000); } handler中 private Handler mHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { // 广告 case HOME_AD_RESULT: auto_viewpager.setCurrentItem(auto_viewpager.getCurrentItem() + 1, true);//设置播放下一页 break; } } }; 其中比较重要的就是viewpager滑动监听的三个回调方法,注释上都有详细的解释,相信看了这个以后小白应该也会手写一个简单的无限自动轮播功能了。是不是简明易懂0.0 源码地址,直接导入modul即可

优秀的个人博客,低调大师

自己用到的Android 双服务保活(适配8.0)

最近开发的时候,测试小伙伴经常来找我,“为什么咱家程序放到后台,聊了会qq就得重启了呢?”我脑门一亮,“稍等,一会给你”。然后我就进入了程序流氓(进程保活)之旅。 对于进程保活,其实吧,现在对于MIUI、EMUI等等许多高度定制的系统并没有100%的保活方案,该死还是死掉,但是做了一定的操作,还是可以适当的提高存活的。如下就是我用到的保活方案。 1、启动软件的时候激活本地服务和远程服务 startService (new Intent (this, MainService.class)); startService (new Intent (this, RemoteService.class)); 2、本地服务代码 /** * content:后台运行的服务 * Actor:韩小呆 * Time:2018/5/3 */ public class MainService extends Service { MyBinder binder; MyConn conn; @Override public IBinder onBind(Intent intent) { return binder; } @Override public void onCreate() { super.onCreate(); binder = new MyBinder(); conn = new MyConn(); } class MyBinder extends IMyAidlInterface.Stub { @Override public String getServiceName() throws RemoteException { return MainService.class.getSimpleName(); } } @Override public int onStartCommand(Intent intent, int flags, int startId) { this.bindService(new Intent(MainService.this, RemoteService.class), conn, Context.BIND_IMPORTANT); return START_STICKY; } class MyConn implements ServiceConnection { @Override public void onServiceConnected(ComponentName name, IBinder service) { } @Override public void onServiceDisconnected(ComponentName name) { Intent intent = new Intent(MainService.this, RemoteService.class); if (Build.VERSION.SDK_INT >= 26) { \\适配8.0机制 MainService.this.startForegroundService(intent); } else { MainService.this.startService(intent); } //绑定远程服务 MainService.this.bindService(new Intent(MainService.this, RemoteService.class), conn, Context.BIND_IMPORTANT); } } @Override public void onDestroy() { super.onDestroy(); Intent intent = new Intent(MainService.this, RemoteService.class); \\适配8.0机制 if (Build.VERSION.SDK_INT >= 26) { MainService.this.startForegroundService(intent); } else { MainService.this.startService(intent); } MainService.this.bindService(new Intent(MainService.this, RemoteService.class), conn, Context.BIND_IMPORTANT); } } 3、远程服务代码 /** * content:后台运行的服务 * Actor:韩小呆 * Time:2018/5/3 */ public class RemoteService extends Service { MyConn conn; MyBinder binder; @Override public IBinder onBind(Intent intent) { return binder; } @Override public void onCreate() { super.onCreate(); conn = new MyConn(); binder = new MyBinder(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { this.bindService(new Intent(this, MainService.class), conn, Context.BIND_IMPORTANT); return START_STICKY; } class MyBinder extends IMyAidlInterface.Stub { @Override public String getServiceName() throws RemoteException { return RemoteService.class.getSimpleName(); } } class MyConn implements ServiceConnection { @Override public void onServiceConnected(ComponentName name, IBinder service) { } @Override public void onServiceDisconnected(ComponentName name) { Intent intent = new Intent(RemoteService.this, MainService.class); //开启本地服务 if (Build.VERSION.SDK_INT >= 26) { \\适配8.0机制 RemoteService.this.startForegroundService(intent); } else { RemoteService.this.startService(intent); } //绑定本地服务 RemoteService.this.bindService(new Intent(RemoteService.this, MainService.class), conn, Context.BIND_IMPORTANT); } } @Override public void onDestroy() { super.onDestroy(); Intent intent = new Intent(RemoteService.this, MainService.class); //开启本地服务 if (Build.VERSION.SDK_INT >= 26) { \\适配8.0机制 RemoteService.this.startForegroundService(intent); } else { RemoteService.this.startService(intent); } //绑定本地服务 RemoteService.this.bindService(new Intent(RemoteService.this, MainService.class), conn, Context.BIND_IMPORTANT); } } 4、创建AIDL实现远近程服务通信 // Declare any non-default types here with import statements interface IMyAidlInterface { String getServiceName(); } AIDL文件

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

用户登录
用户注册
修改密码
忘记密码