国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
(圖文)android UI 優(yōu)化系之windowBackground 一

 你知道嗎?windowBackground會影響到Activity的繪制速度! 
        而我們在開發(fā)android應(yīng)用時,很多時候并沒有注意到這些。因為我們大多數(shù)時候,不會更改Activity主題風(fēng)格,于是android使用默認(rèn)的主題風(fēng)格。而這個主題風(fēng)格中就包含有一個 windowBackground。這個默認(rèn)的主題風(fēng)格定義在frameworks\base\core\res\res\values\themes.xml 中,如下: 

  1. <style name="Theme">  
  2. <item name="colorForeground">@android:color/bright_foreground_dark</item>  
  3. <item name="colorForegroundInverse">@android:color/bright_foreground_dark_inverse</item>  
  4. <item name="colorBackground">@android:color/background_dark</item>  
  5. <item name="colorBackgroundCacheHint">?android:attr/colorBackground</item>  
  6. <item name="disabledAlpha">0.5</item>      
  7. <item name="backgroundDimAmount">0.6</item>
  8. ......
  9. <item name="windowBackground">@android:drawable/screen_background_dark</item>        
  10. <item name="windowFrame">@null</item>        
  11. <item name="windowNoTitle">false</item>      
  12. <item name="windowFullscreen">false</item>        
  13. <item name="windowIsFloating">false</item>      
  14. <item name="windowContentOverlay">@android:drawable/title_bar_shadow</item>        
  15. <item name="windowShowWallpaper">false</item>      
  16. ......

 
 
這個默認(rèn)的 windowBackground 定義為screen_background_dark,可以在frameworks\base\core\res\res\values\colors.xml 中找到,定義為:<drawable name="screen_background_dark">#ff000000</drawable> 
 
我們首先來看看windowBackground 對程序的影響,然后再找出影響的原因。 
 
1.新建一個叫做windowBackground的工程,其它步驟略。注意由于沒有修改主題,所以工程中的activity使用默認(rèn)的主題風(fēng)格。下面在res/layout/main.xml 中添加一個FpsImageView,如下: 

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--  This layout does not use <merge/> to slow down the drawing --><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent">
  3.     <com.example.android.window.FpsImageView        android:layout_width="fill_parent"        android:layout_height="fill_parent"                android:src="@drawable/antelope_canyon"        android:scaleType="center" />
  4.     <TextView        android:id="@+id/title"            android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center_horizontal|bottom"        android:layout_marginBottom="12dip"                android:padding="12dip"                android:background="#90000000"        android:textAppearance="?android:attr/textAppearanceLarge"        android:text="Antelope Canyon" />        
  5. </FrameLayout>

 
其中的FpsImageView繼承自ImageView,在其中增加了 幀率的計算。在activity中不停的調(diào)用postInvalidate以使得FpsImageView不停的繪制,從而顯示出幀率。FpsImageView代碼如下: 

  1. public class FpsImageView extends ImageView {
  2.     private long mStartTime = -1;
  3.     private int mCounter;
  4.     private int mFps;
  5.     private final Paint mPaint;
  6.     
  7.     public FpsImageView(Context context, AttributeSet attrs) {
  8.         super(context, attrs);
  9.         
  10.         mPaint = new Paint();
  11.         mPaint.setColor(0xFFFFFFFF);
  12.         mPaint.setAntiAlias(true);
  13.     }
  14.     @Override
  15.     public void draw(Canvas canvas) {
  16.         if (mStartTime == -1) {
  17.             mStartTime = SystemClock.elapsedRealtime();
  18.             mCounter = 0;
  19.         }
  20.         long now = SystemClock.elapsedRealtime();
  21.         long delay = now - mStartTime;
  22.         super.draw(canvas);
  23.         
  24.         canvas.drawText(mFps + " fps", 100, 50, mPaint);
  25.         if (delay > 1000L) {
  26.             mStartTime = now;
  27.             mFps = mCounter;
  28.             mCounter = 0;
  29.         }
  30.         
  31.         mCounter++;
  32.     }
  33. }

 
 
運行程序,得到如下結(jié)果: 

 
可以看到目前的幀率大概在44 左右。 
 
 
2.修改AndroidManifest.xml,為activity指定主題,即不使用默認(rèn)主題,在activity標(biāo)簽內(nèi)添加一行: 
android:theme="@style/Theme.NoBackground" 
其中的 Theme.NoBackground 定義在res/values/theme.xml中,如下: 

  1. <?xml version="1.0" encoding="utf-8"?><resources>    <style name="Theme.NoBackground" parent="android:Theme">        <item name="android:windowBackground">@null</item>    </style></resources>

 
 
 
從theme.xml中可以看出,它將android:windowBackground置為null了,使用此主題,我們的activity講沒有背景  運行程序,得到如下結(jié)果: 

 

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
安卓手機(jī)全局背景美化教程。
android_002_04: 自定義主題樣式
Android根據(jù)Button狀態(tài)(normal,focused,pressed)顯示不同...
Delphi XE5開發(fā)的Android啟動時黑屏解決方法
自定義progressdialog
自定義 RadioButton 選中和未選中時的圖片
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服