Android Small UI实际应用总结

    技术2022-05-20  50

    一、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属性。

     

     

     

     

     

     

     

     

     

     

     

     


    最新回复(0)