Android UI 使用更快更高效

举报
ShaderJoy 发表于 2021/12/30 02:06:14 2021/12/30
【摘要】 之前有谈过如何使用adapter更高效的,现在在谈谈其他的。 一、选择恰当的图像尺寸   视图背景图总是会填充整个视图区域,图像尺寸的不适合会导致图像的自动缩放,为了避免这种情况,我们可以先将图片进行缩放到视图的大小。 originalImage = Bitmap.createScaledBitmap(original...


一、选择恰当的图像尺寸


  视图背景图总是会填充整个视图区域,图像尺寸的不适合会导致图像的自动缩放,为了避免这种情况,我们可以先将图片进行缩放到视图的大小。


  
  1. originalImage = Bitmap.createScaledBitmap(
  2. originalImage, //被缩放图
  3. view.getWidth(), //视图宽度
  4. view.getHeight(), //视图高度
  5. true //双限行过滤器
  6. );

二、去掉不需要的默认窗口背景






1.代码实现:


  
  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) {
  3. // TODO Auto-generated method stub
  4. super.onCreate(savedInstanceState);
  5. setContentView(R.layout.main);
  6. //删除窗口背景
  7. getWindow().setBackgroundDrawable(null);
  8. }

2.xml里实现:



  
  1. <resources>
  2. <style name="NoBackGroundTheme" parent="android:Theme">
  3. <item name="android:windowBackground">@null</item>
  4. </style>
  5. </resources>


  
  1. <activity android:name="MyActivity" android:theme="@style/NoBackGroundTheme">
  2. ......
  3. </activity>

三、尽可能的使用简单的布局和视图







1.使用TextView的复合drawables,减少层次



  
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:orientation="horizontal" android:layout_width="fill_parent"
  3. android:layout_height="fill_parent">
  4. <TextView android:layout_width="fill_parent"
  5. android:layout_height="wrap_content" android:text="@string/hello" />
  6. <Image android:layout_width="wrap_content"
  7. android:layout_height="wrap_content" android:id="@+id/image" android:background="@drawable/icon" />
  8. </LinearLayout>


  
  1. <TextView android:layout_width="fill_parent"
  2. android:layout_height="wrap_content" android:text="@string/hello" android:drawableRight="@drawable/icon"/>

2.使用ViewStub延迟展开视图


<ViewStub android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/vs" android:layout="@layout/main"/>
 

findViewById(R.id.vs).setVisibility(View.VISIBLE);
 

或者
findViewById(R.id.vs).inflate();
 

3.使用<merge>合并视图






  
  1. <merge
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent">
  6. .....
  7. </merge>





文章来源: panda1234lee.blog.csdn.net,作者:panda1234lee,版权归原作者所有,如需转载,请联系作者。

原文链接:panda1234lee.blog.csdn.net/article/details/8831172

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

举报
请填写举报理由
0/200