首页 文章 精选 留言 我的

精选列表

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

Java程序性能优化9

使用移位操作来代替'a / b'操作 "/"是一个很“昂贵”的操作,使用移位操作将会更快更有效。 例子:public class SDIV { public static final int NUM = 16; public void calculate(int a) { int div = a / 4; // should be replaced with "a >> 2". int div2 = a / 8; // should be replaced with "a >> 3". int temp = a / 3; } } 更正:public class SDIV { public static final int NUM = 16; public void calculate(int a) { int div = a >> 2; int div2 = a >> 3; int temp = a / 3; // 不能转换成位移操作 } }

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

Android布局优化----ViewStub、include、merge

1 StubView 作用:StubView标签中的布局只有在需要的时候才会被渲染加载。 注意:StubView的渲染加载操作只能执行一次;不支持merge标签 使用示例: (1)ViewStub中引用的布局 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <? xml version = "1.0" encoding = "utf-8" ?> < LinearLayout android:id = "@+id/stublayout" xmlns:android = "http://schemas.android.com/apk/res/android" android:orientation = "vertical" android:layout_width = "match_parent" android:layout_height = "match_parent" > < TextView android:id = "@+id/sbtv" android:layout_width = "300dp" android:layout_height = "300dp" android:text = "thisissubtextview" /> </ LinearLayout > (2)使用ViewStub 1 2 3 4 5 < ViewStub android:id = "@+id/viewstub" android:layout_width = "100dp" android:layout_height = "100dp" android:layout = "@layout/sublayout" /> (3)java代码中渲染加载 1 2 3 4 ViewStubstub=(ViewStub)findViewById(R.id.viewstub); stub.inflate(); TextViewstubtv=(TextView)layout.findViewById(R.id.sbtv); stubtv.setText( "hellostub!" ); 2 include标签 作用:将引用的布局替换到当前布局中该标签所处的位置; 注意:引用的布局非merge,设置inlude的id属性后会覆盖掉引用布局顶层layout的id; 示例1 引用布局非merge (1)引用布局 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <? xml version = "1.0" encoding = "utf-8" ?> < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:id = "@+id/sharedlayout2" android:layout_width = "200dp" android:layout_height = "200dp" android:background = "@android:color/black" > < TextView android:id = "@+id/mytv" android:layout_width = "100dp" android:layout_height = "100dp" android:background = "@android:color/holo_blue_light" android:text = "这时一个公用的布局" /> </ LinearLayout > (2)使用include标签 1 2 3 4 5 <include android:id= "@+id/include1" <!--该id会覆盖布局( 1 )中LinearLayout的id;--> layout= "@layout/my" android:layout_width= "50dp" android:layout_height= "50dp" ></include> (3)java中使用 1 2 3 LinearLayoutsharedlayout=(LinearLayout)findViewById(R.id.include1); TextViewtv=(TextView)sharedlayout.findViewById(R.id.mytv); tv.setText( "helloinclude1" ); 示例2 引用merge布局 (1)引用布局 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 < merge xmlns:android = "http://schemas.android.com/apk/res/android" > < LinearLayout android:id = "@+id/mergetlayout" android:layout_width = "wrap_content" android:layout_height = "wrap_content" > < TextView android:id = "@+id/mergetv1" android:layout_width = "40dp" android:layout_height = "40dp" android:background = "@android:color/holo_blue_bright" android:text = "mergetext1" /> < TextView android:id = "@+id/mergetv2" android:layout_width = "40dp" android:layout_height = "40dp" android:background = "@android:color/darker_gray" android:text = "mergetext2" /> </ LinearLayout > </ merge > (2)include标签:merge布局没有id属性,所以这里的id其实没有意义 1 2 3 < include android:id = "@+id/include2" layout = "@layout/mymerge" ></ include > (3)java中使用 1 2 3 4 5 //LinearLayoutlayout=(LinearLayout)findViewById(R.id.include2);//通过该代码无法获取(1)中的LinearLayout,这里的layout为null TextViewmTV1=(TextView)findViewById(R.id.mergetv1); mTV1.setText( "hellomergetv1" ); TextViewmtv2=(TextView)findViewById(R.id.mergetv2); mtv2.setText( "hellomergetv2" ); 3 merge标签 merge标签相当于控件的简单集合,被include到其他布局中后根据所处容器布局结合各个控件的相关属性进行布局。 注意:merge标签没有id属性 使用示例: (1)merge布局 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 < merge xmlns:android = "http://schemas.android.com/apk/res/android" > < TextView android:id = "@+id/mergetv1" android:layout_width = "40dp" android:layout_height = "40dp" android:background = "@android:color/holo_blue_bright" android:text = "mergetext1" /> < TextView android:id = "@+id/mergetv2" android:layout_width = "40dp" android:layout_height = "40dp" android:background = "@android:color/darker_gray" android:text = "mergetext2" /> </ merge > 此时的布局为两个textview重叠并且mergetv2处于上层; (2)merge标签使用 1 2 3 < include android:id = "@+id/include2" layout = "@layout/mymerge" ></ include > (3)由于该include标签处于一个竖直的linearlayout中,此时merge布局的显示效果如下: merge text 1 merge text 2 (4)java中使用 1 2 3 4 TextViewmTV1=(TextView)findViewById(R.id.mergetv1); mTV1.setText( "hellomergetv1" ); TextViewmtv2=(TextView)findViewById(R.id.mergetv2); mtv2.setText( "hellomergetv2" ); 本文转自wauoen51CTO博客,原文链接:http://blog.51cto.com/7183397/1847175 ,如需转载请自行联系原作者

资源下载

更多资源
腾讯云软件源

腾讯云软件源

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

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应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册