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>

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM