bitmap xml大小 安卓_Android实现波浪线效果(xml bitmap)

我们要实现的效果如下:

在这之前先带大家了解一下xml bitmap,何为XML Bitmap?

XML Bitmap是一个用XML定义的文件放在资源目录,定义的对象是图片,为bitmap定义别名,这个文件可以给bitmap定义一些额外的属性。例如:抖动。

1、文件存放位置

res/drawable/filename.xml

2、语法

xmlns:android="http://schemas.android.com/apk/res/android"

android:src="@[package:]drawable/drawable_resource"

android:antialias=["true" | "false"]

android:dither=["true" | "false"]

android:filter=["true" | "false"]

android:gravity=["top" | "bottom" | "left" | "right" | "center_vertical" |

"fill_vertical" | "center_horizontal" | "fill_horizontal" |

"center" | "fill" | "clip_vertical" | "clip_horizontal"]

android:tileMode=["disabled" | "clamp" | "repeat" | "mirror"] />

例子:

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:background="@drawable/bm"

android:text="sssssssssssssssssss" />

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:background="@drawable/bm"

android:text="sssssssssssssssssss" />

效果图:

默认(@drawable/btn_default_pressed_holo_light):

引用(\@drawable/bm):

从截图上就可以看出来差别。

titileMode="repeat":

之后找了一些关于实现波浪线的方法,总感觉不大满意,常见的方法分享给大家:

1、直接搞一个这样的波浪线的切图

这种方式最简单,但是劣势也非常明显,如果view的宽度过大,则会出现图片变形,如下图所示:

如果过小则如下:

要求不高的话,这样勉强可以蒙混过关,但是追求完美的话,这样的效果显然很不给力

2、自定义控件绘制

这个方法的确可以达到不错的效果,但是实现比较麻烦。我也看到有朋友搞过,

3、用xml的bitmap标签实现波浪线效果

首页要搞一个周期的波浪线,即包括波峰和波谷,如下图所示:

wave_item:

然后水平方向上平铺,从而实现波浪线效果,代码如下:

wave.xml:

android:antialias="true"

android:src="@drawable/wave_item"

android:tileMode="repeat" />

activity_main.xml

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingTop="@dimen/activity_vertical_margin" >

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/wave" />

注意:这个ImageView通过background显示图片,src是显示不了这样的效果的。

希望本文所述对大家学习Android软件编程有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值