Android中shape的使用

2021-06-28 01:02:25 字數 1447 閱讀 1545

在看很多開源**中都使用到了shape,我看**的時候一般都一帶而過了,沒有仔細去研究,這幾天剛好有空就順帶詳細了解一下,在學習的過程中參考了官方文件和網上的示例**,本文後面會附上測試**。

一、在res/drawable資料夾下建立乙個名為gradient_box的xml檔案:

<?xml version="1.0" encoding="utf-8"?>

xmlns:android=""

android:shape="rectangle">

android:radius="8dp"

android:topleftradius="5dp"

android:toprightradius="15dp"

android:bottomleftradius="20dp"

android:bottomrightradius="25dp"  

/>

android:startcolor="#ffff0000"

android:endcolor="#80ff00ff"

android:angle="45"

/> 

android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp"

/>

android:width="600dp"

/>

android:color="#ffff9d77"

/>

android:width="2dp"

android:color="#dcdcdc"  

/> 

二、在視窗布局檔案中將步驟一中建立的檔案作為textview的背景:

<?xml version="1.0" encoding="utf-8"?>

xmlns:android=""

android:layout_width="fill_parent"

android:layout_height="fill_parent">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="shapetest"

android:background="@drawable/gradient_box"

android:textsize="24.0dp"

android:textcolor="@android:color/black"

/>

3

三、執行效果展示:

關於android裡面Shape屬性的使用

shape屬性 shape的中文意思是模型,形狀。android裡面的shape也是這個意思,它的存在就是為了為給使用者自定義圖形的提供解決方案。總而言之,你可以用它自定義做一些一些簡單的圖形。好像扯的有點多,嗯嗯,好吧,直接說用法吧 在工程上右鍵新建android xml檔案進入建立頁面,選擇re...

android使用shape使元件呈現特殊效果

android radius 10dp android startcolor 33cc00 android endcolor 666600 android angle 45 android left 5dp android top 5dp android right 5dp android bott...

Android中shape的使用

本人在美工方面一直是比較白痴的,對於一些顏色什麼亂七八糟的非常頭痛,但是在android程式設計中這又是經常涉及到的東西,沒辦法,只有硬著頭皮上。android中常常使用shape來定義控制項的一些顯示屬性,今天看了一些shape的使用,對shape有了大體的了解,稍作總結 先看下面的 solid ...