Android UI設計中的三種特效

來源:互聯網
上載者:User

標籤:android   背景色   ui設計   

一、背景色漸層

背景色漸層可以通過在res/drawable中定義一個XML檔案實現,gradient.xml的代碼如下:



<?xml version="1.0" encoding="utf-8"?>  

<shape xmlns:android="http://schemas.android.com/apk/res/android">  

    <gradient   

    android:startColor="#FFFFFF"  

    android:endColor="#000000"  

    android:angle="45"/>  

</shape>  

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">    <gradient android:startColor="#FFFFFF"android:endColor="#000000"android:angle="45"/></shape>


其中,shape是用來定義形狀的,gradient定義該形狀裡面為漸層色填充,startColor起始顏色,endColor結束顏色,angle表示方向角度。當angle=0時,漸層色是從左向右。 然後逆時針方向轉,當angle=45時為從左下到右上,當angle=90時為從下往上。

然後,設定Activity的背景為:android:background="@drawable/gradient",這樣即可實現背景色漸層效果,如下:

650) this.width=650;" src="http://hi.csdn.net/attachment/0_1309356672ULRX.gif" />

二、標題列進度條

在後台線程中執行各種操作(網路連接、大資料存放區)的時候,我們希望讓客戶能看到後台有操作在進行,那麼既能有效提示使用者,又不佔用當前操作空間,最好的方法就是在標題列有個進度條。實現的方法很簡單,代碼如下:



public void onCreate(Bundle savedInstanceState) {  

    super.onCreate(savedInstanceState);  

     // 先給Activity註冊介面進度條功能     

     requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);  

     setContentView(R.layout.main);  

     // 在需要顯示進度條的時候調用這個方法  

     setProgressBarIndeterminateVisibility(true);  

     // 在不需要顯示進度條的時候調用這個方法  

     //setProgressBarIndeterminateVisibility(false);  

     setContentView(R.layout.main);  

}  

public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     // 先給Activity註冊介面進度條功能       requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);     setContentView(R.layout.main);     // 在需要顯示進度條的時候調用這個方法     setProgressBarIndeterminateVisibility(true);     // 在不需要顯示進度條的時候調用這個方法     //setProgressBarIndeterminateVisibility(false);     setContentView(R.layout.main);    }


如下(注意圖中紅線標註的地方):

650) this.width=650;" src="http://hi.csdn.net/attachment/0_1309357395RmH5.gif" />

三、介面邊框圓角

介面邊框圓角的實現方式同樣是在res/drawable中定義一個XML檔案,corners.xml的代碼如下:



  1. <?xml version="1.0" encoding="utf-8"?>  

  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">    

  3.     <solid android:color="#FF9900" />    

  4.     <corners android:topLeftRadius="10dp"   

  5.         android:topRightRadius="10dp"    

  6.         android:bottomRightRadius="10dp"   

  7.         android:bottomLeftRadius="10dp"/>    

  8. </shape>  

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">      <solid android:color="#FF9900" />      <corners android:topLeftRadius="10dp"    android:topRightRadius="10dp"          android:bottomRightRadius="10dp"        android:bottomLeftRadius="10dp"/>  </shape>


其中,solid的表示填充顏色,而corners則是表示圓角,注意的是這裡bottomRightRadius是左下角而不是右下角,bottomLeftRadius右下角。

然後,在Activity中設定背景為上面的xml,android:background="@drawable/corners",這樣即可實現邊框圓角。效果如下:

650) this.width=650;" src="http://hi.csdn.net/attachment/0_1309356683L6fc.gif" />


Android UI設計中的三種特效

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.