android:shape妙用

來源:互聯網
上載者:User

標籤:

android:shape這個檔案或者說屬性是控制組件特性特別有用,往上搜刮的內容講解很迂腐,還是自己上手試了一下才感覺稍微入了門,不多說,上代碼。

布局檔案送上:<!-- lang: java --><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity" ><Button     android:id="@+id/btnTest"    android:layout_width="100dp"    android:layout_height="100dp"    android:text="組件"    android:layout_centerInParent="true"    />

Button的原始特性![可以看出,照片很呆板][1][1]: http://static.oschina.net/uploads/space/2015/0301/141755_uycv_734421.jpg下面介紹shape裡第一個屬性:gradient ,這個屬性工作表示,組件內部顏色的漸層,漸層由android:startColor和android:endColor來實現,這個很好理解,另外一個很重要的標籤是漸層的角度android:angle,這個比較難,讓我們上手看看,

首先Button需要先引用shape.xml這個檔案,接下來我設定了四個比較典型的角度:0度,45度,90度,180度,看圖。

<gradient     android:startColor="#000"    //結束漸層顏色黑色    android:endColor="#FFF"   //起始漸層顏色白色    android:angle=""   //漸層角度    /> ![0度][2]![45度][3]![45度][4]![90度][5]![180度][6]漸層方向和角度的關係已經很明顯了。corners:本義是角落,在android裡角,就是四個角,這個屬性很簡單,只有半徑這個標籤需要記住 <!-- lang: java --> <!-- 組件圓角以及角半徑 --><!-- radius後邊屬性會覆蓋android:radius  --> <corners     android:radius="10dp"    android:topLeftRadius="10dp"      android:topRightRadius="20dp"    android:bottomLeftRadius="30dp"    //bottomLeftRadius和bottomRightRadius兩個屬性是顛倒的,這個需要注意    android:bottomRightRadius="40dp"    /> stroke:就是border,邊框,搜到的文檔都叫描邊,雲裡霧裡啊看的,<!-- lang: java --><stroke     android:color="#FF0000"   //邊框顏色    android:width="4dp"        //邊框寬度    android:dashWidth="4dp"    //虛線邊框寬度    android:dashGap="10dp"    //虛線邊框寬度    />


附贈一個外國人的黑技術~

android:shape妙用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.