《Android开发艺术探索》笔记——Drawable
来源:互联网 发布:汽车电脑编程语言 编辑:程序博客网 时间:2024/06/16 01:49
BitmapDrawable
bitmap_drawable.xml
<?xml version="1.0" encoding="utf-8"?><bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@mipmap/ic_launcher" android:antialias="true" android:dither="true" android:filter="true" android:gravity="center" android:tileMode="repeat" ></bitmap>
ShapeDrawable
shape_dash_drawable.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/colorAccent"/> <stroke android:dashGap="2dp" android:dashWidth="10dp" android:width="2dp" android:color="@color/colorPrimary"/></shape>
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="9" android:useLevel="false"> <gradient android:endColor="#2F90BD" android:startColor="#FFFFFF" android:type="sweep" /> </shape>
LayerDrawable
layer_drawable.xml
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="#0ac39e" /> </shape> </item> <item android:bottom="6dp"> <shape android:shape="rectangle"> <solid android:color="#ffffff" /> </shape> </item> <item android:bottom="1dp" android:left="1dp" android:right="1dp"> <shape android:shape="rectangle"> <solid android:color="#ffffff" /> </shape> </item></layer-list>
LevelListDrawable
level_list_drawable.xml
<?xml version="1.0" encoding="utf-8"?><level-list xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@mipmap/dir1" android:maxLevel="1"/> <item android:drawable="@mipmap/dir2" android:maxLevel="2"/> <item android:drawable="@mipmap/dir3" android:maxLevel="3"/> <item android:drawable="@mipmap/dir4" android:maxLevel="4"/></level-list>
TransitionDrawable
transition_drawable.xml
<?xml version="1.0" encoding="utf-8"?><transition xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@color/white"/> <item android:drawable="@color/colorPrimaryDark"/></transition>
InsetDrawable
inset_drawable.xml
<?xml version="1.0" encoding="utf-8"?><inset xmlns:android="http://schemas.android.com/apk/res/android" android:insetBottom="20dp" android:insetLeft="20dp" android:insetRight="20dp" android:insetTop="20dp" > <shape android:shape="rectangle"> <solid android:color="@color/colorPrimary"/> <stroke android:color="@color/white"/> </shape> </inset>
ScaleDrawable
scale_drawable.xml
<?xml version="1.0" encoding="utf-8"?><scale xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@mipmap/ic_launcher" android:scaleHeight="70%" android:scaleWidth="70%"></scale>
ClipDrawable
clip_drawable.xml
<?xml version="1.0" encoding="utf-8"?><clip xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@mipmap/ic_launcher" android:clipOrientation="vertical" android:gravity="top"></clip>
activity_drawable.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/shape_dash_drawable" > <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ImageView android:layout_width="200dp" android:layout_height="200dp" android:src="@drawable/shape_ring_drawable"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:padding="2dp" android:background="@drawable/layer_drawable"/> <ImageView android:id="@+id/iv_level_list" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/level_list_drawable" /> <TextView android:id="@+id/tv_transition" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="55555555555555555" android:background="@drawable/transition_drawable"/> <ImageView android:layout_width="100dp" android:layout_height="100dp" android:background="@drawable/inset_drawable" android:id="@+id/imageView" /> <ImageView android:id="@+id/iv_scale" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/scale_drawable"/> <ImageView android:id="@+id/iv_clip" android:layout_width="100dp" android:layout_height="100dp" android:src="@drawable/clip_drawable"/> </LinearLayout> </ScrollView></LinearLayout>
DrawableActivity
public class DrawableActivity extends AppCompatActivity { private ImageView iv_level_list; private TextView tv_transition; private ImageView iv_scale; private ImageView iv_clip; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawable); iv_level_list = (ImageView) findViewById(R.id.iv_level_list); iv_level_list.setImageLevel(4); tv_transition = (TextView) findViewById(R.id.tv_transition); TransitionDrawable transitionDrawable = (TransitionDrawable) tv_transition.getBackground(); transitionDrawable.startTransition(1000); iv_scale = (ImageView) findViewById(R.id.iv_scale); ScaleDrawable scaleDrawable = (ScaleDrawable) iv_scale.getBackground(); scaleDrawable.setLevel(5); iv_clip = (ImageView) findViewById(R.id.iv_clip); ClipDrawable clipDrawable = (ClipDrawable) iv_clip.getDrawable(); //0-10000 clipDrawable.setLevel(5000); }}
0 0
- 《Android开发艺术探索》笔记——Drawable
- Android开发艺术探索-Drawable
- Android 开发艺术探索笔记 第六章 Android的Drawable
- 开发艺术探索-- Drawable
- Android开发艺术探索第六章——Android的Drawable
- 《Android开发艺术探索》——笔记(一)
- 《Android开发艺术探索》笔记
- 《Android开发艺术探索》笔记
- 开发艺术探索阅读笔记—01
- 开发艺术探索阅读笔记—02
- Android开发艺术探索<Drawable系列之一BitmapDrawable>
- Android开发艺术探索<Drawable系列之二ShapeDrawable>
- Android开发艺术探索<Drawable系列之三LayerDrawable>
- Android开发艺术探索<Drawable系列之四StateListDrawable >
- Android开发艺术探索<Drawable系列之五ScaleDrawable >
- Android开发艺术探索<Drawable系列之六ClipDrawabe >
- 第六章Andorid的Drawable(Android开发艺术探索)
- Android开发艺术探索_Android的Drawable(六)
- 大小写·字母的转换
- maven的简单使用<个人笔记>
- 全排列问题(Form)&组合的输出(Compages) 题解
- 如何用CSS3做地月模型
- ABP入门系列(8)——Json格式化
- 《Android开发艺术探索》笔记——Drawable
- PHP之简单在线文件管理
- 单片机知识总结(一)
- 如何知道目录及子目录下文件的数量
- lock和synchronized的同步区别与选择
- Spring Boot如何让Web API自动生成文档,并解决swagger-annotations的API注解description属性废弃的问题
- Cgroup 理解
- 前端开发之JavaScript实战应用
- tomcat原理及安装及反向代理、会话保持、session集群和session共享服务器的实现(一)