首页 文章 精选 留言 我的

精选列表

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

Thinking in Google Doc - ActionBar讲解

对于ActionBar,谷歌文档介绍了2种写法,其中2.1是带v7包。 对于3.0(使用系统自带的主题) ---带应用的icon If you've created a custom theme, be sure it uses one of theTheme.Holothemes as its parent. android:theme="@android:style/Theme.Holo" 对于2.1带v7包(使用v7包里的主题) ---不带应用的icon 第1:Activity要继承自ActionBarActivity 第2:Activity的主题必须是AppCompat <activity android:theme="@style/Theme.AppCompat.Light" ... > publicclassMainActivityextendsActionBarActivity{...} 千万要注意的问题:AppCompatActivity必须与AppCompat的主题配合使用,不能混搭。 >>>>对于使用了支持库的,有一个问题需要注意一下: 只有AppComatActivity才有showAsAction这个属性,Activity只有菜单,并不会将菜单里的条目做 成Action。 If your app is using the Support Libraryfor compatibility on versions as low as Android 2.1, theshowAsActionattribute is not available from theandroid:namespace. Instead this attribute is provided by the Support Library and you must define your own XML namespace and use that namespace as the attribute prefix. (A custom XML namespace should be based on your app name, but it can be any name you want and is only accessible within the scope of the file in which you declare it.) For example: res/menu/main_activity_actions.xml <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:yourapp="http://schemas.android.com/apk/res-auto" > <!-- Search, should appear as action button --> <item android:id="@+id/action_search" android:icon="@drawable/ic_action_search" android:title="@string/action_search" yourapp:showAsAction="ifRoom" /> ...</menu> >>>>为Activity增加返回按钮: 方式1:隐式的进行绑定 先配置Activity,包括它的父Activity(也就是它返回跳转到的那个Activity) <!-- A child of the main activity --><activity android:name=".Activity2" android:label="@string/title_activity_display_message" android:parentActivityName=".MainActivity" > <!-- Parent activity meta-data to support 4.0 and lower --> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity" /></activity> 然后 (BundlesavedInstanceState){ .onCreate(savedInstanceState)setContentView(R.layout.)getSupportActionBar().setDisplayHomeAsUpEnabled()} 》》Styling the Action Bar(做出有风格的ActionBar) 1.Use an Android Theme ###不使用支持库的情况 Theme.Holofor a "dark" theme. 工具栏和主面板都是黑色主题(API11) Theme.Holo.Lightfor a "light" theme. 工具栏和主面板都是白色主题 (API11) Theme.Holo.Light.DarkActionBar 工具栏为黑色,主面板为白色(API14 When using the Support Library, you must instead use theTheme.AppCompatthemes: Theme.AppCompatfor the "dark" theme. Theme.AppCompat.Lightfor the "light" theme. Theme.AppCompat.Light.DarkActionBarfor the light theme with a dark action bar 2.Customize the Background 3.Customize the Text Color 4.Customize the Tab Indicator 上面的我也没有写,具体请看谷歌文档Develop-Training-Adding Action Bar-Styling the ActionBar >>Overlaying the Action Bar(使ActionBar堆叠在主面板之上) 这样做的好处:一旦ActionBar hide或者show的时候,不会引起主界面的重绘,效率高。 需要考虑的一个问题:主面板要设置个margin,不让ActionBar遮盖住主界面。 android:paddingTop="?android:attr/actionBarSize" 本文转自屠夫章哥 51CTO博客,原文链接:http://blog.51cto.com/4259297/1715680,如需转载请自行联系原作者

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

Thinking in Google Doc-不同设备适配

对于Android开发,适配主要指下面3个方面: 1.语言适配 国际化,最基本的方法是建立多个string.xml文件。 另外,肯定有其它国际化的方法 。 2.屏幕适配(包括layout和bitmaps适配) 3.版本适配(在低版本平台上运行高版本API) 使用Android Support Library这个支持库 The Android Support Library package is a set of code libraries(一系列代码库的集合) ----- v4 Support Library 如ViewPager、Fragment -----Multidex Support Library http://blog.csdn.net/t12x3456/article/details/40837287 解决集成sdk重复类的问题 -----v7 Support Libraries |------v7 appcompat library 如ActionBar,AppcompatActivity |------v7 cardview library |-----v7 gridlayout library |------v7 recyclerview library -----V8、V13、V17,所谓的V指的就是Version。 -----Annotations Support Library -----Design Support Library 兼容性更广,直接可以向下兼容到Android 2.2 支持Meterial Design,做出更炫的界面。 http://www.androidchina.net/1381.html 对于MeterialDesign里的各个组件作了详细的介绍 http://blog.csdn.net/eclipsexys/article/details/46349721 Snackbar使用及其注意事项http://www.jcodecraeer.com/plus/view.php?aid=3187 TextInputLayout FloatingActionButton 圆形按钮http://blog.csdn.net/lmj623565791/article/details/46678867 相当于一个ImageView TabLayout http://www.bubuko.com/infodetail-977938.html(简单地实现页面滑动) NavigationView 导航界面的(封装了头布局和菜单布局) AppBarLayout 对ToolBar和TabLayout的封装 CollapsingToolbarLayout 可以折叠的ToolBar 本文转自屠夫章哥 51CTO博客,原文链接:http://blog.51cto.com/4259297/1715677,如需转载请自行联系原作者

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

Thinking in Google Doc-图片框架的实现及布局优化

学习谷歌文档,总结如下: 1.图片加载框架的封装 1)利用HttpURLConnection来封装网络加载图片的方法 2)创建自定义的AsyncTask来封装1)中加载网络图片的方法,并显示到控件上。 3)暴露方法封装2)中自定义的加载并显示图片的AsyncTask 走完上面这几步,只需调用一个方法,就可以从网络上加载一张图片并且显示到控件上了。 解决List并发下载图片错位的问题 但是,谷歌文档中说上面代码会存在一个问题。就是如果在List里使用,复用的话,可能会发生图 图片错位的问题:就是某个item显示的图片,可能显示的图片是之前的item的图片。因为之前的这 张图片可能加载时间比较长,滑动后imageview是复用的,所以后面的item可能会显示之前的item的 图片。 这种就是由于并发产生的问题,谷歌工程师是这么解决问题的: 1》定义一个类 class DownloadedDrawable extends ColorDrawable,然后将下载的异步任务 DownloadAsyncTask与其绑定起来。 1 2 3 4 5 6 7 8 9 10 11 12 13 public static void display(Contextcontext,Stringurl,ImageViewimageView){ BitmapbitmapFromMemCache=LruCacheUtil.getBitmapFromMemCache(url); if (bitmapFromMemCache!= null ){ imageView.setImageBitmap(bitmapFromMemCache); } else { if (cancelPotentialDownload(url,imageView)){ BitmapDownloaderTasktask= new BitmapDownloaderTask(context,imageView); DownloadedDrawabledownloadedDrawable= new DownloadedDrawable(task); imageView.setImageDrawable(downloadedDrawable); task.execute(url); } } } 2》定义2个方法 BitmapDownloaderTask getBitmapDownloaderTask(ImageView imageView) --得到与ImageView绑定的异步下载任务 1 2 3 4 5 6 7 8 9 10 public static BitmapDownloaderTaskgetBitmapDownloaderTask(ImageViewimageView){ if (imageView!= null ){ Drawabledrawable=imageView.getDrawable(); if (drawable instanceof DownloadedDrawable){ DownloadedDrawabledownloadedDrawable=(DownloadedDrawable)drawable; return downloadedDrawable.getBitmapDownloaderTask(); } } return null ; } boolean cancelPotentialDownload(String url, ImageView imageView) --取消可能正在进行的下载,并返回是否已经取消。 如果与imageView绑定的下载任务不为空,再判断与ImageView绑定的异步下载任务的URL,如果 为null或者是与当前方法传递进来URL不一致,说明异步下载任务正在执行之前的下载,就取消任 务,否则说明任务正在执行中且url一致,就不重新开启任务。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 private static boolean cancelPotentialDownload(Stringurl,ImageViewimageView){ BitmapDownloaderTaskbitmapDownloaderTask=BitmapDownloaderTask.getBitmapDownloaderTask(imageView); if (bitmapDownloaderTask!= null ){ StringbitmapUrl=bitmapDownloaderTask.url; if ((bitmapUrl== null )||(!bitmapUrl.equals(url))){ bitmapDownloaderTask.cancel( true ); } else { //ThesameURLisalreadybeingdownloaded. return false ; } } return true ; } 解决图片缓存的问题 1》用内存来缓存,使用LruCache这个类。 内存的特点: 内存加载速度比较快,但是内存在开关机之后会被回收,缓存的数据会消失。 底层: LinkedHashMap来实现存储 实现原理: 当从url下载图片之前,先判断缓存中存不存在图片,如果存在直接加载图片,不存在则 去网络请求图片。 当AsyncTask下载完图片之后,如果不为null,就存放到缓存中。 于是我写了个工具类LruCacheUtils来完成图片的缓存 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 public class LruCacheUtil{ //LruCacheforbitmap private static LruCache<String,Bitmap>mMemoryCache; static { //GetmaxavailableVMmemory,exceedingthisamountwillthrowan //OutOfMemoryexception.StoredinkilobytesasLruCachetakesan //intinitsconstructor. final int maxMemory=( int )(Runtime.getRuntime().maxMemory()/ 1024 ); //Use1/8thoftheavailablememoryforthismemorycache. final int cacheSize=maxMemory/ 8 ; mMemoryCache= new LruCache<String,Bitmap>(cacheSize){ @TargetApi (Build.VERSION_CODES.HONEYCOMB_MR1) @Override protected int sizeOf(Stringkey,Bitmapbitmap){ //Thecachesizewillbemeasuredinkilobytesratherthan //numberofitems. return bitmap.getByteCount()/ 1024 ; } }; } public static void addBitmapToMemoryCache(Stringkey,Bitmapbitmap){ if (getBitmapFromMemCache(key)== null ){ mMemoryCache.put(key,bitmap); } } public static BitmapgetBitmapFromMemCache(Stringkey){ return mMemoryCache.get(key); } } 2》使用磁盘(Disk)来缓存,使用DiskLruCache(这个类google文档里并没有提供) Android DiskLruCache 源码解析 硬盘缓存的绝佳方案 http://blog.csdn.net/lmj623565791/article/details/47251585 下载链接 http://http://www.oschina.net/p/disklrucache Android本地缓存DiskLruCache完整详细学习示例 http://www.2cto.com/kf/201501/368172.html 虽然利用内存来缓存,加载图片的时候速度比较快,但是像GridView会很快地占满内存。当应 用非正常关闭(如被电话应用打断、运行在后台的时候被杀死)会导致cache被销毁清空。 注意:获取图片应该在后台进行 Of course, fetching images from disk is slower than loading from memory and should be done in a background thread, as disk read times can be unpredictable.(from google doc) 缓存位置: 有外部存储设备就存放到外部存储设备中,否则存放到应用包名目录下。 2.布局优化 sdk下的一些工具并不是专门针对Eclipse的,Android Studio也可以使用。 sdk/tools下的工具Hierarchy Viewer http://wear.techbrood.com/training/improving-layouts/optimizing-layout.html#Inspect 爽处1:可以查看布局结构某个节点的3个方法Measure、Layout、Draw执行所需要的时间,这样 如果某个item的加载时间比较长,你就应该要优化了。 使用这个工具可能会遇到的问题: 问题:使用Hierarchyviewer,measure、layout、draw时间未显示? 解决办法:点击菜单ProfileNode,重新加载之后就有了 用Hierarchyviewer,measure、layout、draw时间未显示? 本文转自屠夫章哥 51CTO博客,原文链接:http://blog.51cto.com/4259297/1710561,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

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

Nacos

Nacos

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

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册