[置顶] Android(安卓)Small UI实际应用总结
一、Android UI 加速
1、如果某个activity使用了图片作为背景,因为同时默认情况下窗口有一个不透明的背景,删除窗口背景。
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.screen_shelves); getWindow().setBackgroundDrawable(null);//提高效率 }
2、在视图和布局方面加速UI
(1)使用ViewStub延迟展开视图
(2)使用merge合并中间视图
(3)使用RelativeLayout减少层次
(4)使用自定义视图和布局
(5)使用TextView的drawable××属性,减少层次,如android:drawableLeft,可以在TextView左边放置一个drawable
==============================================================================================================================
二、Android UI使用技巧
1、在Button中放置一张图片,或者在文字的四周放上图片。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="测试TextView的drawable" android:id="@+id/mess" android:drawableLeft="@drawable/icon" android:drawablePadding="20dip" /> <Button android:drawableLeft="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:drawableLeft="@drawable/icon&<mce:script type="text/javascript" src="http://hi.images.csdn.net/js/blog/tiny_mce/themes/advanced/langs/zh.js" mce_src="http://hi.images.csdn.net/js/blog/tiny_mce/themes/advanced/langs/zh.js"></mce:script><mce:script type="text/javascript" src="http://hi.images.csdn.net/js/blog/tiny_mce/plugins/syntaxhl/langs/zh.js" mce_src="http://hi.images.csdn.net/js/blog/tiny_mce/plugins/syntaxhl/langs/zh.js"></mce:script>quot; android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="测试1" /> <Button android:drawableLeft="@drawable/icon" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="测试2" /> <Button android:drawableLeft="@drawable/icon" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="测试长度要长" /> </LinearLayout>
2、让TextView带有下划线
<resources> <string name="hello"><u>phone: 1390123456</u></string> <string name="app_name">MyLink</string> </resources>
TextView textView = (TextView)findViewById(R.id.testView); textView.setText(Html.fromHtml("<u>"+"hahaha"+"</u>"));
3、获取焦点,得到点击相应 android:descendantFocusability
属性值:
beforeDescendants:viewGroup会优于其他控件而获取到焦点
afterDescendants: viewGroup只有子控件不需要的时候才获取焦点
blockDescendants: ViewGroup会覆盖子类控件而直接获取焦点
如果在ListView的item布局中用到了button checkable的子控件,如果使用listview的onitemclickListener的时候,不会相应这个click。这时候就可以使用blockDescendants属性。
更多相关文章
- android include 控件详解
- ListView分页(带图片)显示用法案例
- android视图层的设计 javacode版本 有图哦
- VideoView重绘
- Android中的WebView控件用法
- Android(安卓)PullToRefresh (ListView GridView 下拉刷新) 使用详
- 项目中平时遇到的小知识点集锦
- android 比较有用的方法总结
- 用Crosswalk的XWalkView做混合式App