1. 程式人生 > >android 畫虛線、實線,畫圓角矩形,一半圓角

android 畫虛線、實線,畫圓角矩形,一半圓角

1、畫虛線,實線


建立dotted_line_gray.xml檔案放在drawable資料夾下面。

android:shape="line" 可以修改你想要的形狀


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="line">
     <!-- 顯示一條虛線,破折線的寬度為dashWith,破折線之間的空隙的寬度為dashGap,當dashGap=0dp時,為實線 -->
   <stroke android:width="1dp" android:color="#D5D5D5"    
             android:dashWidth="2dp" android:dashGap="3dp" />   
             <!-- 虛線的高度 --> 
     <size android:height="2dp" />    
</shape>


然後在佈局的xml裡面:
作為ImageView或者Linearlayout等作為背景源就可以了。
<LinearLayout
            android:id="@+id/activity_line"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dip"
            android:layout_marginRight="5dip"
            android:background="@drawable/dotted_line_gray" />
---------


2、畫圓角矩形


建立 rect_gray.xml檔案放在drawable資料夾下面。


<?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="#D5D5D5"></stroke>        
   
    <!-- 矩形的圓角半徑 -->
    <corners android:radius="0dp" />       
            
</shape>
然後在佈局的xml裡面:
作為ImageView或者Linearlayout等作為背景源就可以了。
<LinearLayout
                    android:id="@+id/activity_myhezu_wantchuzu"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/myhezu_dottedline_rect_green"
                    android:orientation="horizontal" >


3、一半圓角

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
        <corners  android:topLeftRadius="16dp" <!--上面左圓角的半徑-->
              android:topRightRadius="16dp"          <!--上面右圓角的半徑-->
              android:bottomLeftRadius="0dp"         <!--下面左圓角的半徑-->

              android:bottomRightRadius="0dp"/>   <!--下面右圓角的半徑-->

        <gradient android:startColor="#ffffff" 
              android:endColor="#ffffff"
              android:angle="270"/>

        <stroke   android:width="1dp" 
              android:color="#80000000" /> 
        </shape>