Android設定虛線、圓角、漸層

來源:互聯網
上載者:User

有圖又真相,先再說。

點擊效果:

設定虛線:

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="line" >    <stroke        android:dashGap="3dp"        android:dashWidth="6dp"        android:width="1dp"        android:color="#63a219" /><!-- 虛線的高度 -->    <size android:height="1dp" /></shape>

其中,破折線的寬度為dashWith,破折線之間的空隙的寬度為dashGap,當dashGap=0dp時,為實線

設定圓角:

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle">    <!-- 填充顏色 -->    <solid android:color="#FFFFFF"></solid>    <!-- 線的寬度,顏色灰色 -->    <stroke android:width="1dp" android:color="#63a219"></stroke>            <!-- 矩形的圓角半徑 -->    <corners android:radius="10dp" />       </shape>

設定漸層填充和四個圓角半徑:

<shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle">    <!--分別對應上面左圓角的半徑,上面右圓角的半徑,下面左圓角的半徑,下面右圓角的半徑-->    <corners            android:topLeftRadius="0dp"          android:topRightRadius="7dp"          android:bottomLeftRadius="0dp"          android:bottomRightRadius="7dp"/>    <!--設置漸變-->    <gradient android:startColor="#9cff00"           android:endColor="#197600"          android:angle="270"/>    <stroke           android:width="1dp"         android:color="#63a219" /> </shape>

設定漸層點擊效果:

<style name="list_item_top"><item name="android:clickable">true</item><item name="android:focusable">true</item><item name="android:paddingTop">10dip</item><item name="android:paddingBottom">10dip</item><item name="android:paddingLeft">10dip</item>    <item name="android:paddingRight">10dip</item>    <item name="android:gravity">center_vertical</item>    <item name="android:background">@drawable/background_view_rounded_top</item></style>

<?xml version="1.0" encoding="UTF-8"?><inset xmlns:android="http://schemas.android.com/apk/res/android"    android:insetLeft="1.0px"    android:insetRight="1.0px" >    <selector>        <item android:state_pressed="true">            <shape>                <gradient                    android:angle="270.0"                    android:endColor="@color/base_end_color_pressed"                    android:startColor="@color/base_start_color_pressed" />                <corners                    android:bottomLeftRadius="0.0dip"                    android:bottomRightRadius="0.0dip"                    android:radius="2.0dip"                    android:topLeftRadius="10.0dip"                    android:topRightRadius="10.0dip" />                                <stroke                     android:width="1dp"                     android:color="#eededede" />            </shape>        </item>        <item>            <shape>                <gradient                    android:angle="270.0"                    android:endColor="@color/base_end_color_default"                    android:startColor="@color/base_start_color_default" />                <corners                    android:bottomLeftRadius="0.0dip"                    android:bottomRightRadius="0.0dip"                    android:radius="2.0dip"                    android:topLeftRadius="11.0dip"                    android:topRightRadius="11.0dip" />                                <stroke                     android:width="1dp"                     android:color="#eededede" />            </shape>        </item>    </selector></inset>

源碼免費:免費下載

http://download.csdn.net/detail/lan410812571/5925371

聯繫我們

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