android 使用shape做有边框背景的方法搜集整理
2015-05-07 17:17
351 查看
方法 1
方法2
方法3 ,在高分屏下可能会有问题,解决方法是把-1dp换成-1px。最好的方法是为不同密度屏幕设置不同的密度资源文件【dimension resources】dimens.xml
方法4,这应该是hack, angle 0=left 90=bottom 180=right 270=top
方法61: A border.xml shape, which is just a solid shape in the color of your border: border.xml
方法7 最长常用的方法,就是使用9-patch文件,这个不属于shape总结:方法 1 3 6 原理应该大致相同
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- This is the line --> <item> <shape> <solid android:color="#535353" /> </shape> </item> <!-- This is the main color --> <item android:bottom="1dp"> <shape> <solid android:color="#252525" /> </shape> </item> </layer-list>
方法2
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- This is the line --> <item> <shape> <padding android:left="0dp" android:top="1dp" android:right="0dp" android:bottom="1dp"/> <solid android:color="#898989" /> </shape> </item> <!-- This is the main color --> <item> <shape> <solid android:color="#ffffff" /> </shape> </item> </layer-list>
方法3 ,在高分屏下可能会有问题,解决方法是把-1dp换成-1px。最好的方法是为不同密度屏幕设置不同的密度资源文件【dimension resources】dimens.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- This is the line --> <item android:top="-1dp" android:right="-1dp" android:left="-1dp"> <shape> <solid android:color="@android:color/transparent" /> <stroke android:width="1dp" android:color="#ffffff" /> </shape> </item> </layer-list>
方法4,这应该是hack, angle 0=left 90=bottom 180=right 270=top
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:angle="0" android:startColor="#f00" android:centerColor="@android:color/transparent" android:centerX="0.01" /> </shape>方法5
<?xml version="1.0" encoding="utf-8"?> <inset xmlns:android="http://schemas.android.com/apk/res/android" android:insetTop="-2dp" android:insetBottom="-2dp" android:insetLeft="-2dp"> <shape android:shape="rectangle"> <stroke android:width="2dp" android:color="#FF0000" /> <solid android:color="#000000" /> </shape> </inset>
方法61: A border.xml shape, which is just a solid shape in the color of your border: border.xml
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#ff0000"/> </shape>2: The 'inner' shape, the shape where you want the border to appear around: inner.xml
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#00ff00"/> </shape>3: A layer list, which will put these 2 on top of eachother. You create the border by setting the padding on the inner shape: layerlist.xml
<?xml version="1.0" encoding="UTF-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/border"/> <item android:drawable="@drawable/inner" android:top="3dp" android:right="0dp" android:bottom="3dp" android:left="3dp" /> </layer-list>
方法7 最长常用的方法,就是使用9-patch文件,这个不属于shape总结:方法 1 3 6 原理应该大致相同
相关文章推荐
- 史上最全selector和shape使用方法 Android ListView 列表项点击之后,保持背景颜色
- android控件-ImageView使用方法整理
- Android通过用代码画虚线椭圆边框背景来学习一下shape的用法
- Android编程使用自定义shape实现shadow阴影效果的方法
- Android 使用shape定义不同控件的的颜色、背景色、边框色
- Android实现圆角边框,shape的使用详解以及常用效果
- Android开发之Shape的使用(为TextView等空间添加边框)
- Android 使用shape添加边框
- Android通过用代码画虚线椭圆边框背景来学习一下shape的用法
- Android通过用代码画虚线椭圆边框背景来学习一下shape的用法
- Android 使用Shape自定义背景
- android shape的使用 边框
- android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)
- Android开发,使用背景图(xml drawable)为view 设置边框
- android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)
- android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)
- Android TextView 使用随机背景颜色的方法
- 在android开发中使用multdex的方法-IT蓝豹为你整理
- 在android开发中使用multdex的方法-IT蓝豹为你整理
- 在android开发中使用multdex的方法-IT蓝豹为你整理