Android:shape、XML绘图

简介:

1.线line:

1
2
3
4
5
6
7
8
<?xml version= "1.0"  encoding= "utf-8" ?>
<shape xmlns:android= "http://schemas.android.com/apk/res/android"
     android:shape= "line" >
     <stroke android:width= "8dp"
         android:color= "#ff00ff00"
         android:dashWidth= "6dp"
         android:dashGap= "2dp" />
</shape>


2.椭圆oval:

1
2
3
4
5
6
<?xml version= "1.0"  encoding= "utf-8" ?>
<shape xmlns:android= "http://schemas.android.com/apk/res/android"
     android:shape= "oval" >
     <solid android:color= "#ff345678" />
     <stroke android:width= "20dp"  android:color= "#ff876543" />
</shape>


3.长方形rectangle:

1
2
3
4
5
6
7
8
9
10
11
<?xml version= "1.0"  encoding= "utf-8" ?>
<shape xmlns:android= "http://schemas.android.com/apk/res/android"
     android:shape= "rectangle" >
     <size android:width= "200dp"
         android:height= "300dp" />
     <solid android:color= "#ff665544" />
     <stroke android:width= "20dp"
         android:color= "#445566"
         android:dashWidth= "40dp"
         android:dashGap= "5dp" />
</shape>


4.填充颜色solid、渐变gradient、边角corners:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?xml version= "1.0"  encoding= "utf-8" ?>
<shape xmlns:android= "http://schemas.android.com/apk/res/android"
     android:shape= "rectangle" >
     <size android:width= "200dp"
         android:height= "300dp" />
     <solid android:color= "#ff665544" />
     <stroke android:width= "20dp"
         android:color= "#445566"
         android:dashWidth= "40dp"
         android:dashGap= "5dp" />
         <gradient android:startColor= "#ff5533aa"
             android:centerColor= "#ff996633"
             android:endColor= "#ff114477"
             android:angle= "135"
         />
         <corners
             android:topLeftRadius= "45dp"
             android:topRightRadius= "45dp"
             android:bottomLeftRadius= "135dp"
             android:bottomRightRadius= "135dp" />
                               
             <!-- android:radius= "45dp"  -->
             <!--  渐变角度 只能被 45 整除  -->
</shape>




5.代码编写

1
2
3
4
5
6
7
8
9
//白色背景shape
int  strokeWidth =  5 // 3dp
int  roundRadius =  15 // 8dp
int  strokeColor = Color.parseColor( "#2E3135" );
int  fillColor = Color.parseColor( "#DFDFE0" );
GradientDrawable gd =  new  GradientDrawable();
gd.setColor(fillColor);
gd.setCornerRadius(roundRadius);
gd.setStroke(strokeWidth, strokeColor);






本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1226254,如需转载请自行联系原作者

目录
相关文章
|
Android开发 开发者
Android自定义View之不得不知道的文件attrs.xml(自定义属性)
本文详细介绍了如何通过自定义 `attrs.xml` 文件实现 Android 自定义 View 的属性配置。以一个包含 TextView 和 ImageView 的 DemoView 为例,讲解了如何使用自定义属性动态改变文字内容和控制图片显示隐藏。同时,通过设置布尔值和点击事件,实现了图片状态的切换功能。代码中展示了如何在构造函数中解析自定义属性,并通过方法 `setSetting0n` 和 `setbackeguang` 实现功能逻辑的优化与封装。此示例帮助开发者更好地理解自定义 View 的开发流程与 attrs.xml 的实际应用。
444 2
Android自定义View之不得不知道的文件attrs.xml(自定义属性)
|
XML API PHP
Android使用XML-RPC实现blog客户端
Android使用XML-RPC实现blog客户端
311 2
|
XML JavaScript Android开发
【Android】网络技术知识总结之WebView,HttpURLConnection,OKHttp,XML的pull解析方式
本文总结了Android中几种常用的网络技术,包括WebView、HttpURLConnection、OKHttp和XML的Pull解析方式。每种技术都有其独特的特点和适用场景。理解并熟练运用这些技术,可以帮助开发者构建高效、可靠的网络应用程序。通过示例代码和详细解释,本文为开发者提供了实用的参考和指导。
649 15
|
XML Android开发 数据格式
Android中利用shape属性自定义设置Button按钮
Android中利用shape属性自定义设置Button按钮
702 0
|
XML Android开发 UED
"掌握安卓开发新境界:深度解析AndroidManifest.xml中的Intent-filter配置,让你的App轻松响应scheme_url,开启无限交互可能!"
【8月更文挑战第2天】在安卓开发中,scheme_url 通过在`AndroidManifest.xml`中配置`Intent-filter`,使应用能响应特定URL启动或执行操作。基本配置下,应用可通过定义特定URL模式的`Intent-filter`响应相应链接。
618 12
|
存储 Java 数据库
基于全志H713 Android 11:给TvSettings添加default.xml默认值
本文介绍了在全志H713 Android 11平台上为TvSettings应用添加HDMI CEC功能的默认设置值的方法,通过修改SettingsProvider的源码和配置文件来实现默认值的设置,并提供了详细的步骤和测试结果。
993 0
基于全志H713 Android 11:给TvSettings添加default.xml默认值
|
Shell Android开发
安卓scheme_url调端:在AndroidManifest.xml 中如何配置 Intent-filter?
为了使Android应用响应vivo和oppo浏览器的Deep Link或自定义scheme调用,需在`AndroidManifest.xml`中配置`intent-filter`。定义启动的Activity及其支持的scheme和host,并确保Activity可由外部应用启动。示例展示了如何配置HTTP/HTTPS及自定义scheme,以及如何通过浏览器和adb命令进行测试,确保配置正确无误。
|
Android开发 开发者
Android UI设计中,Theme定义了Activity的视觉风格,包括颜色、字体、窗口样式等,定义在`styles.xml`。
【6月更文挑战第26天】Android UI设计中,Theme定义了Activity的视觉风格,包括颜色、字体、窗口样式等,定义在`styles.xml`。要更改主题,首先在该文件中创建新主题,如`MyAppTheme`,覆盖所需属性。然后,在`AndroidManifest.xml`中应用主题至应用或特定Activity。运行时切换主题可通过重新设置并重启Activity实现,或使用`setTheme`和`recreate()`方法。这允许开发者定制界面并与品牌指南匹配,或提供多主题选项。
528 6
|
XML 存储 JavaScript
50. 【Android教程】xml 数据解析
50. 【Android教程】xml 数据解析
362 1
|
Android开发
android string.xml文件中的整型和string型代替
android string.xml文件中的整型和string型代替
226 0

热门文章

最新文章