Android 图片平铺
最近项目中遇到了图片底部是锯齿状效果如图:
让美工妹子,做了张底部的完全大图 分辨率 低的手机完全可以 适配,但是 到 高分辨率手机上,图片会失真。所以就引入到今天所说到的平铺技术。让美工妹子吧底部的图片切成一小块,如图:
然后我们在 res drawable 下创建bitmap
`<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/icon_slotmachine_bot"
android:layout_height="wrap_content"
android:tileMode="repeat" />
看到xml 里面代码 src 是 图片引用, 最重要的是设置titlemode 设置“repeat” 重复模式 一切OK
我们把需要设置的 布局 里面 吧 这个bitmap 设置成background
<RelativeLayout
android:id="@+id/slotmachine_rl_bot"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/slotmachine_rl_chine"
android:layout_marginTop="-2dp"
android:background="@drawable/slotmachine_bitmap" >
当我们写到这的时候 感觉 是不是可以用了? 答案 是并不能用 运行过后 会是这种效果
所以我们需要计算一下位置
Drawable drawable = getResources().getDrawable(
R.drawable.icon_slotmachine_bot);
int h = drawable.getIntrinsicHeight();
RelativeLayout.LayoutParams linearParams = (RelativeLayout.LayoutParams) mRlBot
.getLayoutParams();
linearParams.height = h;
mRlBot.setLayoutParams(linearParams);
好久没写blog 了 好了今天就到这里了,有什么问题可以留言!