Android:drawable:shape 简单概括总结

2016年01月14日 Android 11条评论 阅读4173次

Android:drawable:shape 简单概括总结

shape已经用过不少了,但感觉每次用到还需要上网搜资料自己猜能完全写出来,所以认为还有必要拿出来简单总结一下。

shape下面的标签有以下六个。

  • corners
  • gradient
  • padding
  • size
  • solid
  • stroke

这六个标签下,又有不同的各自所属属性。接下来一个个地说。

  • corners 圆角效果

    • android:radius 整体设置四个角的圆角半径[dimension]
    • android:bottomLeftRadius
    • android:bottomRightRadius
    • android:topLeftRadius
    • android:topRightRadius

    单独设置某个角的圆角半径[dimension],可以只用第一个为四个角设置同样的圆角半径,也可以用四个方位角分别设置。

    如果不希望有圆角效果,这个corners可以完全不写。

  • gradient 渐变效果

    • android:angle="45"
    • android:centerColor="#888888"
    • android:centerX="0"
    • android:centerY="0"
    • android:endColor="@android:color/black"
    • android:gradientRadius="90"
    • android:startColor="@android:color/white"
    • android:type="radial"
    • android:useLevel="false"

    android:angle表示方向角度;当angle=0时,渐变色是从左向右,然后逆时针方向转,当angle=90时为从下往上;angle必须为45的整数倍

    android:gradientRadius表示渐变的半径(当 android:type="radial" 时才使用。单独使用 android:type="radial"会报错)

    android:type可取值为:["linear" | "radial" | "sweep"]

    android:centerX 整型 渐变中心X点坐标的相对位置

    android:centerY 整型 渐变中心Y点坐标的相对位置

    android:useLevel ["true" | "false"] 如果要使用LevelListDrawable对象,就要设置为true。设置为true无渐变。false有渐变色

  • padding 间隔距离

    • android:bottom
    • android:left
    • android:right
    • android:top

    这个和布局中的android:padding 一样理解。也就是控件里面的内容距离控件边框的距离[dimension]

  • size 大小

    • android:height
    • android:width

    这个解释设置该控件到底有多宽有多高了。[dimension]

★注意点1:

若应用的控件在布局文件中设置了android:layout_width="match_parent"/android:layout_height="match_parent"时,则此size设置的宽高属性就会无效。

★注意点2:

若该shape的padding中有设置间距大小,则控件的实际显示大小也会变化,此size设置的宽高属性也会无效。

  • solid 填充颜色

    • android:color

      只有这么一个属性可设置。也就是应用控件的背景颜色。[color]

  • stroke 外围边框

    • android:dashGap
    • android:dashWidth
    • android:width
    • android:color

android:width 外边框的宽度

android:color 外边框的颜色如果想要虚线的外边框,android:dashGap和android:dashWidth要设置,并且任何一个属性都不能为0;

如果不想要虚线的外边框,android:dashGap和android:dashWidth不写,或将其置为0

用一段代码贴出来shape会用到的标签和属性。



<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners
    android:bottomLeftRadius="4dp"
    android:bottomRightRadius="4dp"
    android:radius="45dp"
    android:topLeftRadius="4dp"
    android:topRightRadius="4dp" />
<gradient
    android:angle="45"
    android:centerColor="#888888"
    android:centerX="0"
    android:centerY="0"
    android:endColor="@android:color/black"
    android:gradientRadius="90"
    android:startColor="@android:color/white"
    android:type="radial"
    android:useLevel="true" />
<padding
    android:bottom="5dp"
    android:left="5dp"
    android:right="5dp"
    android:top="5dp" />
<size
    android:height="30dp"
    android:width="80dp" />
<solid android:color="#108008" />
<stroke
    android:dashGap="1dp"
    android:dashWidth="0dp"
    android:width="0dp"
    android:color="@android:color/black" />
</shape>



OK 先总结到这里,以后用到 shape 应该有本文就能基本解决了。

分享本文至:

WRITTEN BY

avatar
本文标签:androidshape
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

11 条评论

  1. avatar donggeomdo

    <a href="http://www.georgesherry.com/dam%C3%A4nner-air-jordan-retro-11-schwarz-gr%C3%BCn-schuheb">dam盲nner air jordan retro 11 schwarz gr眉n</a> <a href="http://www.jenalgroup.com/adidas-jets-8-teemu-selanne-camo-authentic-2017-veterans-day-stitched-nhl-jersey-nflu">adidas jets 8 teemu selanne camo authentic 2017 veterans day stitched nhl jersey</a> <a href="http://www.badacamshotel.com/nike-cortez-gold-metallic-skou">nike cortez gold metallic</a> <a href="http://www.compressmyjs.com/new-balance-577-mens-blue-white-runninge">new balance 577 mens blue white</a> <a href="http://www.fetison.com/uk-trainers-nike-flyknit-racer-fire-rooster-zapatosu">uk trainers nike flyknit racer fire rooster</a> <a href="http://www.neffloot.com/kvinners-nike-free-tr-flyknit-5.0-gr%C3%A5-r%C3%B8d-chaussuresa">kvinners nike free tr flyknit 5.0 gr氓 r酶d</a>
    donggeomdo http://www.donggeomdo.com/

  2. avatar ehisem

    <a href="http://www.calendarxs.com/hombres-nike-flyknit-racer-oro-p%C3%BArpura-butyg">hombres nike flyknit racer oro p煤rpura</a> <a href="http://www.elindigo.com/nike-foamposite-one-royal-bleu-2010-retro-scarpea">nike foamposite one royal bleu 2010 retro</a> <a href="http://www.fabrykabarwy.com/nike-mercurial-superfly-wei%C3%9F-volt-motor-schuheb">nike mercurial superfly wei脽 volt motor</a> <a href="http://www.fonepsi.com/nike-air-jordan-2-blanc-rouge-butyf">nike air jordan 2 blanc rouge</a> <a href="http://www.jehleflowers.com/asics-gel-hyper-33-orange-jaune-butyf">asics gel hyper 33 orange jaune</a> <a href="http://www.ksmartcity.com/air-jordan-29-lila-blau-obuvf">air jordan 29 lila blau</a>
    ehisem http://www.ehisem.com/

  3. avatar stalksdesign

    <a href="http://www.blockboymusic.com/billig-nike-free-3.0-v2-herre-gr%C3%A5-sneakere">billig nike free 3.0 v2 herre gr氓</a> <a href="http://www.aquaboutic.com/jeremiah-sirles-78-jersey-xl-nfld">jeremiah sirles 78 jersey xl</a> <a href="http://www.plusjulesmumm.com/air-max-reflective-adidas-shoesc">air max reflective adidas</a> <a href="http://www.tomscave.com/air-jordan-future-red-michael-jordan-skof">air jordan future red michael jordan</a> <a href="http://www.casagranderox.com/air-jordan-retro-14-wolf-grey-sport-blue-van-sportse">air jordan retro 14 wolf grey sport blue van</a> <a href="http://www.clumsford.com/nike-free-3.0-v4-black-cheetah-runningd">nike free 3.0 v4 black cheetah</a>
    stalksdesign http://www.stalksdesign.com/

  4. avatar yankaripark

    <a href="http://www.heslaatours.com/nike-kyrie-1-grigio-blu-lava-key-kurpesa">nike kyrie 1 grigio blu lava key</a> <a href="http://www.prostekrasna.com/nike-shox-deliver-women-sneakerb">nike shox deliver women</a> <a href="http://www.altharmony.com/air-jordan-4-gray-jordan-af1-shoesg">air jordan 4 gray jordan af1</a> <a href="http://www.cosmicupcake.com/snapback-billabong-hats">snapback billabong</a> <a href="http://www.btmtecled.com/nike-hyperrev-2016-black-green-sneakerf">nike hyperrev 2016 black green</a> <a href="http://www.torcgunstore.com/air-max-thea-r%C3%B8d-kvinners-loafers-obuvc">air max thea r酶d kvinners loafers</a>
    yankaripark http://www.yankaripark.com/

  5. avatar jmgtours

    <a href="http://www.nhadatmoivn.com/nike-free-run-4.0-black-and-red-rom-shoesf">nike free run 4.0 black and red rom</a> <a href="http://www.cakirgozoto.com/zx-flux-shoes-jd-shoesb">zx flux shoes jd</a> <a href="http://www.mozhizhou.com/parajumper-m%C3%B6ssa-parajumpersr">parajumper m枚ssa</a> <a href="http://www.perialetheia.com/coach-prairie-satchel-in-floral-print-leather-coachr">coach prairie satchel in floral print leather</a> <a href="http://www.honestmentor.com/2014-15-real-madrid-2-varane-away-pink-soccer-long-sleeve-shirt-kit-nflv">2014 15 real madrid 2 varane away pink soccer long sleeve shirt kit</a> <a href="http://www.edgethrive.com/nobis-cartel-fit-nobisr">nobis cartel fit</a>
    jmgtours http://www.jmgtours.com/

  6. avatar motiongfxart

    <a href="http://www.ambitionagent.com/nike-flyknit-lunar-3-svart-electric-gr%C3%B8nn-total-oransje-hvit-schuhee">nike flyknit lunar 3 svart electric gr酶nn total oransje hvit</a> <a href="http://www.brensonford.com/adidas-zx-flux-sort-lilla-scarpea">adidas zx flux sort lilla</a> <a href="http://www.dutting.com/adidas-forum-mid-orange-silber-kurpesf">adidas forum mid orange silber</a> <a href="http://www.erickasouza.com/dodgers-22-clayton-kershaw-grey-cool-base-autographed-stitched-mlb-jersey-nflr">dodgers 22 clayton kershaw grey cool base autographed stitched mlb jersey</a> <a href="http://www.flyboardbc.com/air-jordan-melo-wei%C3%9F-rot-kurpesf">air jordan melo wei脽 rot</a> <a href="http://www.mommypads.com/nike-air-max-2015-new-bl%C3%A5-gul-oransje-nails-schuhef">nike air max 2015 new bl氓 gul oransje nails</a>
    motiongfxart http://www.motiongfxart.com/

  7. avatar azhomereports

    <a href="http://www.dragongateusa.com/mk-bedford-medium-mkr">mk bedford medium</a> <a href="http://www.tarabzouni.com/nike-hypervenom-phatal-ii-sg-pro-sportse">nike hypervenom phatal ii sg pro</a> <a href="http://www.aurelmar.com/nike-limited-mens-pittsburgh-steelers-84-antonio-brown-80th-anniversary-throwback-nfl-jersey-89.99-nflv">nike limited mens pittsburgh steelers 84 antonio brown 80th anniversary throwback nfl jersey 89.99</a> <a href="http://www.rivacover.com/nike-free-run-5.0-lime-green-solution-shoesf">nike free run 5.0 lime green solution</a> <a href="http://www.annanilsen.com/air-jordan-1-dam%C3%A4nner-wei%C3%9F-shoesb">air jordan 1 dam盲nner wei脽</a> <a href="http://www.fhomestudio.com/parajumper-herre-parajumpersr">parajumper herre</a>
    azhomereports http://www.azhomereports.com/

  8. avatar ihavewed

    <a href="http://www.praiseti.com/jordan-13-sort-varsity-r%C3%B8d-hvid-vibrant-gul-chaussuresa">jordan 13 sort varsity r酶d hvid vibrant gul</a> <a href="http://www.cynshq.com/limited-linval-joseph-youth-jersey-minnesota-vikings-98-road-white-nfle">limited linval joseph youth jersey minnesota vikings 98 road white</a> <a href="http://www.fnjcompressor.com/nike-air-max-id-2014-runningf">nike air max id 2014</a> <a href="http://www.kifftradingco.com/zdeno-chara-33-boston-bruins-reebok-premier-alternate-jersey-small-nflv">zdeno chara 33 boston bruins reebok premier alternate jersey small</a> <a href="http://www.phaqtory.com/nike-kobe-9-ext-high-trainersa">nike kobe 9 ext high</a> <a href="http://www.cialislaw.com/nike-kobe-10-rosa-s%C3%B8lv-scarpec">nike kobe 10 rosa s酶lv</a>
    ihavewed http://www.ihavewed.com/

  9. avatar skynetankara

    <a href="http://www.printonlipro.com/adidas-zx-flux-white-and-silver-skod">adidas zx flux white and silver</a> <a href="http://www.freonsystem.com/red-purple-mens-nike-kyrie-2-shoes-shoesf">red purple mens nike kyrie 2 shoes</a> <a href="http://www.gamtola.com/billig-adidas-springblade-ignite-herre-s%C3%B8lv-sneakerd">billig adidas springblade ignite herre s酶lv</a> <a href="http://www.diarso.com/nike-sb-x-air-jordan-1-by-lance-mountain-price-footb">nike sb x air jordan 1 by lance mountain price</a> <a href="http://www.dbgbackoffice.com/billig-nike-kobe-11-flyknit-menns-bl%C3%A5-runningd">billig nike kobe 11 flyknit menns bl氓</a> <a href="http://www.warthogrugby.com/prada-sunglasses-sale-online-pradar">prada sunglasses sale online</a>
    skynetankara http://www.skynetankara.com/

  10. avatar milligande

    <a href="http://www.supermarketes.com/cheap-toddler-girl-ugg-boots-uggsr">cheap toddler girl ugg boots</a> <a href="http://www.theblases.com/ray-ban-rb2140-white-sunglassesr">ray ban rb2140 white</a> <a href="http://www.dandoelroll.com/mackage-down-jacket-sale-mackager">mackage down jacket sale</a> <a href="http://www.christinabox.com/bon-march%C3%A9-nike-free-5.0-chaussures-femmes-or-sportsb">bon march茅 nike free 5.0 chaussures femmes or</a> <a href="http://www.segwaycr.com/air-jordan-7-retro-white-grey-blue-purple-light-footc">air jordan 7 retro white grey blue purple light</a> <a href="http://www.amarthur.com/nike-air-max-classic-jaren-90-sneakerc">nike air max classic jaren 90</a>
    [url=http://www.milligande.com/]milligande[/url]

  11. avatar ahlyons

    <a href="http://www.ciarahanna.com/ferragamo-belt-black-friday-sale-beltr">ferragamo belt black friday sale</a> <a href="http://www.ascautoparts.com/adidas-ace-16-sat%C4%B1n-al-skou">adidas ace 16 sat谋n al</a> <a href="http://www.extrasklepik.com/nike-sneakers-dunk-sky-hi-skow">nike sneakers dunk sky hi</a> <a href="http://www.clarencelax.com/chicago-blackhawks-winter-classic-knit-hat-with-pom-hatr">chicago blackhawks winter classic knit hat with pom</a> <a href="http://www.yanginmalzeme.com/hermes-festival-scarf-scarfr">hermes festival scarf</a> <a href="http://www.anitatribune.com/pink-north-face-vest-northfacer">pink north face vest</a>
    ahlyons http://www.ahlyons.com/

欢迎留言




用户登录

sitemap