首页 文章 精选 留言 我的

精选列表

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

Android优化——UI优化(三)使用ViewStub延迟加载

使用ViewStub延迟加载 1.ViewStub延迟加载 ViewStub是一个不可见的,大小为0的View,最佳用途就是实现View的延迟加载,在需要的时候再加载View,可Java中常见的性能优化方法延迟加载一样。 当调用ViewStub的setVisibility函数设置为可见或则调用inflate初始化该View的时候,ViewStub引用的资源开始初始 化,然后引用的资源替代ViewStub自己的位置填充在ViewStub的位置。因此在没有调用setVisibility(int)或则 inflate()函数之前ViewStub一种存在组件树层级结构中,但是由于ViewStub非常轻量级,这对性能影响非常小。 可以通过ViewStub的inflatedId属性来重新定义引用的layout id。 例如: xml <ViewStub android:id="@+id/stub" android:layout_width="match_parent" android:layout_height="match_parent" android:inflatedId="@+id/subTree" android:layout="@layout/activity_viewstub_item"/> java //获取到viewstub final ViewStub stub = (ViewStub) findViewById(R.id.stub); //测试用inflate()填充布局 Handler handler = new Handler() { @Override public void handleMessage(Message msg) { View view = stub.inflate(); } }; handler.sendEmptyMessageDelayed(1, 7000); 我这里间隔了一段时间去调用了stub.inflate();方法,加载布局,我们这里就不用再去findViewById去加载view了 效果 本文转自 一点点征服 博客园博客,原文链接:http://www.cnblogs.com/ldq2016/p/5226583.html,如需转载请自行联系原作者

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

Android:UI控件DrawerLayout、Fragment、SlidingLayout、侧滑菜单

DrawerLayout与Fragment的联用 1.xml代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 <android.support.v4.widget.DrawerLayout xmlns:android= "http://schemas.android.com/apk/res/android" android:id= "@+id/drawer_layout" android:layout_width= "match_parent" android:layout_height= "match_parent" > <FrameLayout android:id= "@+id/fragment_layout" android:layout_width= "match_parent" android:layout_height= "match_parent" > </FrameLayout> <RelativeLayout android:id= "@+id/menu_layout" android:layout_width= "300dp" android:layout_height= "match_parent" android:layout_gravity= "left" android:background= "#ff333333" > <ListView android:id= "@+id/menu_listView" android:layout_width= "match_parent" android:layout_height= "match_parent" > </ListView> </RelativeLayout> </android.support.v4.widget.DrawerLayout> 2.MainActivity继承FragmentActivity 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 import android.os.Bundle; import android.app.Activity; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTransaction; import android.support.v4.widget.DrawerLayout; import android.view.Menu; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.AdapterView.OnItemClickListener; public class MainActivity extends FragmentActivity { /* * DrawerLayout与Fragment的联用 * DrawerLayout相关: * 1.一般内容层使用framelayout * 2.slidingLayout需要设置一个layout_grative属性 * 文档建议使用android:layout_gravity="start" */ public static final String[] TITLES = { "Henry IV (1)" , "Henry V" , "Henry VIII" , "Richard II" , "Richard III" , "Merchant of Venice" , "Othello" , "King Lear" }; private DrawerLayout mDrawer_layout; private RelativeLayout mMenu_layout; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); mDrawer_layout = (DrawerLayout) findViewById(R.id.drawer_layout); mMenu_layout = (RelativeLayout) findViewById(R.id.menu_layout); ListView menu_listview = (ListView) mMenu_layout.findViewById(R.id.menu_listView); menu_listview.setAdapter( new ArrayAdapter<String>( this , android.R.layout.simple_expandable_list_item_1, TITLES)); //监听菜单 menu_listview.setOnItemClickListener( new DrawerItemClickListener()); } public class DrawerItemClickListener implements OnItemClickListener { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); Fragment fragment = null ; //根据item点击行号判断启用哪个Fragment switch (position) { case 0 : fragment = new FirstFragment(); break ; case 1 : fragment = new NextFragment(); break ; default : break ; } ft.replace(R.id.fragment_layout, fragment); ft.commit(); mDrawer_layout.closeDrawer(mMenu_layout); //点击后关闭mMenu_layout } } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true ; } } 3.Fragment类 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class FirstFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = inflater.inflate(R.layout.firstlayout, null ); return layout; } } 1 2 3 4 5 6 7 8 9 public class NextFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = inflater.inflate(R.layout.nextlayout, null ); return layout; } } 本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1229561,如需转载请自行联系原作者

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

Android UI 使用HTML布局(直接打开server网页)

非常多时候我们用HTML布局会更方便直接,记录一下。 我如今主要是直接调用server的网页(实际上是jsp的,仅仅是返回的是html)。所以须要联网,第一步加入权限。 <uses-permission android:name="android.permission.INTERNET" /> 布局文件直接用一个WebView,例如以下: <?xml version="1.0" encoding="utf-8"? > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <WebView android:id="@+id/webView1" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> 以下就能够直接写代码了: package com.yangshidesign.testgryoscope; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.webkit.JavascriptInterface; import android.webkit.WebView; import android.widget.Toast; public class AddEmojiActivity extends Activity { private WebView webView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_addemoji); webView = (WebView) this.findViewById(R.id.webView1); webView.getSettings().setJavaScriptEnabled(true); webView.addJavascriptInterface(new WebPlugin(), "WebPlugin"); webView.loadUrl(this.getString(R.string.server_url)); } /** * 插件类。在html的js里面直接调用 */ private class WebPlugin { @JavascriptInterface public void test() { Log.e("miquan", "kkkkkk"); Toast.makeText(AddEmojiActivity.this, "test toast ", Toast.LENGTH_SHORT).show(); } @JavascriptInterface public String test2() { return "something"; } } } 当中@JavascriptInterface注解是加入在每个须要用到的方法上面的。 最后就能够直接在HTML网页上调用了。 <script type="text/javascript"> function test() { WebPlugin.test(); var something = WebPlugin.test2(); } </script> 本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5224042.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

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

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文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册