Android Api Demos登顶之路(七十五)Graphics-->GradientDrawable
2015-09-19 22:54
405 查看
这个demon主要演示了drawable中shape的用法。
主要在布局文件中引用在drawable中定义的shape
shape1.xml
line.xml
shape2.xml
shape3.xml
shape4.xml
activity_main.xml
主要在布局文件中引用在drawable中定义的shape
shape1.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 用红色填充drawable并为其设置宽度为5dp,颜色为绿色的描边 --> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#ffff0000"/> <stroke android:width="5dp" android:color="#ff00ff00"/> </shape>
line.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 画一条线。这里需要注意的是stroke android:width="2dp" 属性定义的是线的高度 android:dashWidth="5dp" android:dashGap="4dp"表示每段宽5dp间隔4dp的虚线 size android:height="10dp"表示整个drawable的高度,而线在drawable的垂直方向上剧中 所以如果height小于或等于width则线是不可见的 --> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line" > <stroke android:width="2dp" android:color="#ff0000ff" android:dashWidth="5dp" android:dashGap="4dp"/> <size android:height="10dp"/> </shape>
shape2.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 用红色填充drawable并为其设置宽度为5dp,颜色为绿色的虚线描边 设置圆角的半径为4dp padding属性表明在drawable上面显示的内容(比如文字)距离drawable各个边框的距离--> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#ffff0000"/> <stroke android:width="5dp" android:color="#ff00ff00" android:dashWidth="5dp" android:dashGap="4dp"/> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <corners android:radius="4dp" /> </shape>
shape3.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 用红色填充drawable(椭圆形)并为其设置宽度为5dp,颜色为绿色的虚线描边 设置圆角的半径为4dp padding属性表明在drawable上面显示的内容(比如文字)距离drawable各个边框的距离--> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#ffff0000"/> <stroke android:width="5dp" android:color="#ff00ff00" android:dashWidth="5dp" android:dashGap="4dp"/> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <corners android:radius="4dp" /> </shape>
shape4.xml
<?xml version="1.0" encoding="utf-8"?> <!-- 用渐变颜色填充drawable(矩形)设置圆角的半径为8dp padding属性表明在drawable上面显示的内容(比如文字)距离drawable各个边框的距离--> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF" android:angle="270"/> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <corners android:radius="8dp" /> </shape>
activity_main.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <ImageView android:layout_width="match_parent" android:layout_height="50dip" android:src="@drawable/shap_1"/> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/line"/> <ImageView android:layout_width="match_parent" android:layout_height="50dip" android:src="@drawable/shap_2"/> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/line"/> <ImageView android:layout_width="match_parent" android:layout_height="50dip" android:src="@drawable/shap_3"/> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/line"/> <ImageView android:layout_width="match_parent" android:layout_height="50dip" android:src="@drawable/shap_4"/> </LinearLayout> </ScrollView>
相关文章推荐
- android------创建模拟器时不能点CPU/ABI
- Android0919<二十三>(ViewGroup、Animation、Animator、Layout Animations)
- Android学习——Intent传递数据
- Android无限循环ViewPager
- Android基础学习之SlidingMenu(侧滑菜单)
- AS边学边写——day03简单的用户界面
- android
- 解决com.android.dex.DexException: Multiple dex files define Lcom/google/gson/JsonSerializer;
- 使用Android Studio进行本地单元测试(Local Unit Tests)
- [转]android中drawable资源的解释及例子
- Android之AnimationSet
- 当dialog挡住activity时的 键盘隐藏
- 【Android小游戏】安卓小游戏开发(直播手把手系列二)
- Android核心基础-10.通知
- Android Studio 百度地图开发
- Android注释技巧
- Android 动画之一 Drawable Animation —— 逐帧(Frame)动画
- 高速建成Android开发环境ADT-Bundle和Hello World
- 轻松学会android中补间动画
- android的存储