Android:drawable:shape 简单概括总结

2016年01月14日 Android 6条评论 阅读6763次

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
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

6 条评论

  1. avatar moviestellar

    <a href="http://www.squigglecase.com/jordan-10-gr%C3%A5-infrar%C3%B8d-svart-obuvd">jordan 10 gr氓 infrar酶d svart</a> <a href="http://www.hshuixin.com/nike-kaishi-rose-or-obuvg">nike kaishi rose or</a> <a href="http://www.cnnturkcanli.com/air-jordan-retro-5-bianca-viola-verde-schuhef">air jordan retro 5 bianca viola verde</a> <a href="http://www.milkybeer.com/adidas-springblade-sort-and-gr%C3%B8n-arrow-obuve">adidas springblade sort and gr酶n arrow</a> <a href="http://www.adsohold.com/zx-700-night-rojo-kit-butye">zx 700 night rojo kit</a> <a href="http://www.ashevillewigs.com/asics-asics-gel-kayano-20-oransje-svart-obuvd">asics asics gel kayano 20 oransje svart</a>
    moviestellar http://www.moviestellar.com/

  2. avatar mipaneldecontrol

    <a href="http://www.historicsheds.net/nike-tiempo-legend-all-svart-zodiac-sign-kurpesc">nike tiempo legend all svart zodiac sign</a> <a href="http://www.hochschulschrift.net/adidas-prougeator-lz-2-first-grade-scarpec">adidas prougeator lz 2 first grade</a> <a href="http://www.hotvape.net/nike-zoom-pegasus-31-hvit-gr%C3%B8nn-svart-schuhed">nike zoom pegasus 31 hvit gr酶nn svart</a> <a href="http://www.hungate.net/air-max-1-bianca-blu-grigio-obuvf">air max 1 bianca blu grigio</a> <a href="http://www.idreamtan.net/nike-hypershift-gr%C3%B8nn-s%C3%B8lv-butya">nike hypershift gr酶nn s酶lv</a> <a href="http://www.ikkunatehdas.net/adidas-ultra-boost-bl%C3%A5-lyser%C3%B8d-butya">adidas ultra boost bl氓 lyser酶d</a>
    mipaneldecontrol http://www.mipaneldecontrol.net/

  3. avatar dientedeperro

    <a href="http://www.ciaodearborn.com/nike-roshe-one-rojo-gris-zapatosh">nike roshe one rojo gris</a> <a href="http://www.ilrione.com/nike-kd-9-wolf-gr%C3%A5-yarn-scarpea">nike kd 9 wolf gr氓 yarn</a> <a href="http://www.bmthtaxis.com/north-carolina-tar-heels-top-of-the-world-ncaa-sundown-cap-hati">north carolina tar heels top of the world ncaa sundown cap</a> <a href="http://www.delmotkrt.com/le-coq-sportif-chaussures-violet-rose-trainersb">le coq sportif chaussures violet rose</a> <a href="http://www.emutemusic.com/asics-mennns-gel-sendai-2-l%C3%B8ping-sko-svart-kurpesd">asics mennns gel sendai 2 l酶ping sko svart</a> <a href="http://www.kinofrost.com/m%C3%A4nner-nike-dunk-high-schwarz-blood-rot-schuhel">m盲nner nike dunk high schwarz blood rot</a>
    dientedeperro http://www.dientedeperro.com/

  4. avatar soundsofbuzz

    <a href="http://www.dbievents.com/nike-noir-blanc-air-huarache-ultra-trainers-chaussuresh">nike noir blanc air huarache ultra trainers</a> <a href="http://www.ilankocaeli.com/nike-free-og-14-br-hommes-2014-wool-skin-jaune-noir-chaussuresj">nike free og 14 br hommes 2014 wool skin jaune noir</a> <a href="http://www.msignworx.com/m%C3%A4nner-nike-dunk-high-blood-rot-schwarz-schuhek">m盲nner nike dunk high blood rot schwarz</a> <a href="http://www.dianegrams.com/mens-arizona-coyotes-black-throwback-custom-ccm-vintage-hockey-jersey-nflh">mens arizona coyotes black throwback custom ccm vintage hockey jersey</a> <a href="http://www.jobstodayng.com/asics-gel-lyte-all-svart-obuvi">asics gel lyte all svart</a> <a href="http://www.hardcoreboris.com/air-jordan-retro-11-low-white-green-python-shoesj">air jordan retro 11 low white green python</a>
    soundsofbuzz http://www.soundsofbuzz.com/

  5. avatar artstrava

    <a href="http://www.ambitionagent.com/kvinders-ralph-lauren-mesh-polo-sort-lyser%C3%B8d-polox">kvinders ralph lauren mesh polo sort lyser酶d</a> <a href="http://www.brensonford.com/curry-3-chaussure-noir-bleu-schuhed">curry 3 chaussure noir bleu</a> <a href="http://www.dutting.com/adidas-ultra-boost-gris-multicolor-scarpec">adidas ultra boost gris multicolor</a> <a href="http://www.erickasouza.com/69-nike-mike-mcglinchey-jersey-nfl-san-francisco-49ers-backer-long-sleeve-t-shirt-red-nflw">69 nike mike mcglinchey jersey nfl san francisco 49ers backer long sleeve t shirt red</a> <a href="http://www.flyboardbc.com/oilers-97-connor-mcdavid-light-blue-name-number-pullover-nhl-hoodie-nflx">oilers 97 connor mcdavid light blue name number pullover nhl hoodie</a> <a href="http://www.mommypads.com/adidas-tubular-runner-noir-zombie-kurpesa">adidas tubular runner noir zombie</a>
    [url=http://www.artstrava.com/]artstrava[/url]

  6. avatar bacononice

    <a href="http://www.accessmdusa.com/billig-squadron-bl%C3%A5-jordan-13-kurpesf">billig squadron bl氓 jordan 13</a> <a href="http://www.bassenergyfw.com/jordan-12-rot-kurpesa">jordan 12 rot</a> <a href="http://www.blueskycvs.com/jual-nike-air-max-1-sort-chaussuresb">jual nike air max 1 sort</a> <a href="http://www.charlsz.com/nike-free-3.0-unisex-lilla-obuve">nike free 3.0 unisex lilla</a> <a href="http://www.csgostuffdz.com/zx-flux-gr%C3%BCn-weave-chaussuresa">zx flux gr眉n weave</a> <a href="http://www.dutbyduygu.com/nike-free-run-5.0-hvid-edition-butya">nike free run 5.0 hvid edition</a>
    bacononice http://www.bacononice.com/

欢迎留言




用户登录

sitemap