標籤: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的代碼如下:
<?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>
<?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設計中的三種特效