android控件开发之gallery3d酷炫效果(带源码)[亲测有效] -金沙1005

android控件开发之gallery3d酷炫效果(带源码)[亲测有效]privateintegermimagesid[]={r.drawable.ic_1,r.drawable.ic_3,r.drawable.ic_2,r.drawable.ic_4,r.drawable.ic_5};三:gallery控件类缩放,还有透明,等等都在这里设置publicclassfancycoverflowextendsgallery{publicstaticfinalintaction_distance_auto=integer.max_v

private integer mimagesid[] = {

r.drawable.ic_1,

r.drawable.ic_3,

r.drawable.ic_2,

r.drawable.ic_4,

r.drawable.ic_5

};

三:gallery 控件类

缩放,还有透明,等等都在这里设置

public class fancycoverflow extends gallery {

public static final int action_distance_auto = integer.max_value;

/**

  • 图片向上突出,可以通过代码控制,也可以在xml上控制

*/

public static final float scaledown_gravity_top = 0.0f;

/**

  • 图片中间突出

*/

public static final float scaledown_gravity_center = 0.5f;

/**

  • 图片向下突出

*/

public static final float scaledown_gravity_bottom = 1.0f;

private float reflectionratio = 0.3f;

private int reflectiongap = 4;

private boolean reflectionenabled = false;

private float unselectedalpha;

private camera transformationcamera;

private int maxrotation = 0;

private float unselectedscale;

private float scaledowngravity = scaledown_gravity_center;

private int actiondistance;

private float unselectedsaturation;

public fancycoverflow(context context) {

super(context);

this.initialize();

}

public fancycoverflow(context context, attributeset attrs) {

super(context, attrs);

this.initialize();

this.applyxmlattributes(attrs);

}

@suppresslint(“newapi”)

public fancycoverflow(context context, attributeset attrs, int defstyle) {

super(context, attrs, defstyle);

if (build.version.sdk_int >= 11) {

this.setlayertype(layer_type_software, null);

}

this.initialize();

this.applyxmlattributes(attrs);

}

private void initialize() {

this.transformationcamera = new camera();

this.setspacing(0);

}

private void applyxmlattributes(attributeset attrs) {

typedarray a = getcontext().obtainstyledattributes(attrs,

r.styleable.fancycoverflow);

this.actiondistance = a

.getinteger(r.styleable.fancycoverflow_actiondistance,

action_distance_auto);

this.scaledowngravity = a.getfloat(

r.styleable.fancycoverflow_scaledowngravity, 0.5f);

this.maxrotation = a.getinteger(r.styleable.fancycoverflow_maxrotation,

0);

this.unselectedalpha = a.getfloat(

r.styleable.fancycoverflow_unselectedalpha, 0.5f);

this.unselectedsaturation = a.getfloat(

r.styleable.fancycoverflow_unselectedsaturation, 0.0f);

this.unselectedscale = a.getfloat(

r.styleable.fancycoverflow_unselectedscale, 0.75f);

}

public float getreflectionratio() {

return reflectionratio;

}

public void setreflectionratio(float reflectionratio) {

if (reflectionratio <= 0 || reflectionratio > 0.5f) {

throw new illegalargumentexception(

“reflectionratio may only be in the interval (0, 0.5]”);

}

this.reflectionratio = reflectionratio;

if (this.getadapter() != null) {

((fancycoverflowadapter) this.getadapter()).notifydatasetchanged();

}

}

public int getreflectiongap() {

return reflectiongap;

}

public void setreflectiongap(int reflectiongap) {

this.reflectiongap = reflectiongap;

if (this.getadapter() != null) {

((fancycoverflowadapter) this.getadapter()).notifydatasetchanged();

}

}

public boolean isreflectionenabled() {

return reflectionenabled;

}

public void setreflectionenabled(boolean reflectionenabled) {

this.reflectionenabled = reflectionenabled;

if (this.getadapter() != null) {

((fancycoverflowadapter) this.getadapter()).notifydatasetchanged();

}

}

@override

public void setadapter(spinneradapter adapter) {

if (!(adapter instanceof fancycoverflowadapter)) {

throw new classcastexception(fancycoverflow.class.getsimplename()

  • ” only works in conjunction with a “

  • fancycoverflowadapter.class.getsimplename());

}

super.setadapter(adapter);

}

public int getmaxrotation() {

return maxrotation;

}

public void setmaxrotation(int maxrotation) {

this.maxrotation = maxrotation;

}

public float getunselectedalpha() {

return this.unselectedalpha;

}

public float getunselectedscale() {

return unselectedscale;

}

public void setunselectedscale(float unselectedscale) {

this.unselectedscale = unselectedscale;

}

public float getscaledowngravity() {

return scaledowngravity;

}

public void setscaledowngravity(float scaledowngravity) {

this.scaledowngravity = scaledowngravity;

}

public int getactiondistance() {

return actiondistance;

}

public void setactiondistance(int actiondistance) {

this.actiondistance = actiondistance;

}

@override

public void setunselectedalpha(float unselectedalpha) {

super.setunselectedalpha(unselectedalpha);

this.unselectedalpha = unselectedalpha;

}

public float getunselectedsaturation() {

return unselectedsaturation;

}

public void setunselectedsaturation(float unselectedsaturation) {

this.unselectedsaturation = unselectedsaturation;

}

public int preleftoffset = 0;

public int count = 0;

public boolean isplaydraw = true;

@override

protected boolean getchildstatictransformation(view child, transformation t) {

fancycoverflowitemwrapper item = (fancycoverflowitemwrapper) child;

preleftoffset = getchildat(0).getleft();

if (android.os.build.version.sdk_int >= 16) {

item.postinvalidate();

}

final int coverflowwidth = this.getwidth();

final int coverflowcenter = coverflowwidth / 2;

final int childwidth = item.getwidth();

final int childheight = item.getheight();

final int childcenter = item.getleft() childwidth / 2;

final int actiondistance = (this.actiondistance == action_distance_auto) ? (int) ((coverflowwidth childwidth) / 2.0f)
this.actiondistance;

float effectsamount = math.min(

1.0f,

math.max(-1.0f, (1.0f / actiondistance)

  • (childcenter – coverflowcenter)));

t.clear();

t.settransformationtype(transformation.type_both);

if (this.unselectedalpha != 1) {

final float alphaamount = (this.unselectedalpha – 1)

  • math.abs(effectsamount) 1;

t.setalpha(alphaamount);

}

if (this.unselectedsaturation != 1) {

// pass over saturation to the wrapper.

final float saturationamount = (this.unselectedsaturation – 1)

  • math.abs(effectsamount) 1;

item.setsaturation(saturationamount);

}

final matrix imagematrix = t.getmatrix();

// 旋转角度不为0则开始图片旋转.

if (this.maxrotation != 0) {

final int rotationangle = (int) (-effectsamount * this.maxrotation);

this.transformationcamera.save();

this.transformationcamera.rotatey(rotationangle);

this.transformationcamera.getmatrix(imagematrix);

this.transformationcamera.restore();

}

// 缩放.

if (this.unselectedscale != 1) {

final float zoomamount = 1f / 2f * (1 – math.abs(effectsamount))

  • (1 – math.abs(effectsamount))

  • (1 – math.abs(effectsamount)) 0.5f;

final float translatex = childwidth / 2.0f;

final float translatey = childheight * this.scaledowngravity;

imagematrix.pretranslate(-translatex, -translatey);

imagematrix.postscale(zoomamount, zoomamount);

imagematrix.posttranslate(translatex, translatey);

if (effectsamount != 0) {

double point = 0.4;

double translatefactor = (-1f / (point * point)

  • (math.abs(effectsamount) – point)

  • (math.abs(effectsamount) – point) 1)

  • (effectsamount > 0 ? 1 : -1);

imagematrix

.posttranslate(

(float) (viewutil.dp2px(getcontext(), 25) * translatefactor),

0);

}

}

return true;

}

// 绘制顺序,先从左到中间,再从右到中间

@override

protected int getchilddrawingorder(int childcount, int i) {

int selectedindex = getselecteditemposition()

  • getfirstvisibleposition();

if (i < selectedindex) {

return i;

} else if (i >= selectedindex) {

return childcount – 1 – i selectedindex;

} else {

return i;

}

}

private boolean istouchable = true;

public void disabletouch() {

istouchable = false;

}

public void enabletouch() {

istouchable = true;

}

public boolean istouchable() {

return istouchable;

}

@override

public boolean ontouchevent(motionevent event) {

count = 0;

for (int i = 0; i < getchildcount(); i ) {

getchildat(i).invalidate();

}

if (istouchable) {

return super.ontouchevent(event);

} else {

return false;

}

}

@override

public boolean onintercepttouchevent(motionevent event) {

if (istouchable) {

return super.onintercepttouchevent(event);

} else {

return true;

}

}

//

// @override

// public boolean onsingletapup(motionevent e) {

// return false;

// }

// 使快速滑动失效

@override

public boolean onfling(motionevent e1, motionevent e2, float velocityx,

float velocityy) {

return false;

}

四:倒影

reflectiongap 处理图片和倒影之间的间距。

/**

  • grallery 倒影放大操作类

*/

public class myimgview {

/**

  • 添加倒影,原理,先翻转图片,由上到下放大透明度

  • @param originalimage

  • @return

*/

public static bitmap createreflectedimage(bitmap originalimage) {

// the gap we want between the reflection and the original image

final int reflectiongap = 4;

int width = originalimage.getwidth();

int height = originalimage.getheight();

// this will not scale but will flip on the y axis

matrix matrix = new matrix();

matrix.prescale(1, -1);

// create a bitmap with th 《android学习笔记总结 最新移动架构视频 大厂安卓面试真题 项目实战源码讲义》无偿开源 徽信搜索公众号【编程进阶路】 e flip matrix applied to it.

// we only want the bottom half of the image

bitmap reflectionimage = bitmap.createbitmap(originalimage, 0,

height / 2, width, height / 2, matrix, false);

// create a new bitmap with same width but taller to fit reflection

bitmap bitmapwithreflection = bitmap.createbitmap(width,

(height height /4), config.argb_8888);

// create a new canvas with the bitmap that’s big enough for

// the image plus gap plus reflection

js555888金沙老品牌的版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由思创斯整理,转载请注明出处:https://ispacesoft.com/140969.html

(0)

相关推荐

  • 安卓分页加载_分页查询出现重复数据

  • android 设置标题栏背景颜色_窗口标题栏左端图标代表android中沉浸式状态栏的文章已经满大街了,可是在实现某些效果时,还是得各种搜索,测试一通后,最后还常常满足不了要求,即使好不容易在一部手机上满足了需求,放在另外一手机上,发现效果差强人意。今天把自己这几天学到的关于沉浸式状态栏知识进行总结下。问题比如我想实现以下效果:1.同一个activity需要动态变换标题栏和状态栏文字字体色值,该如何实现?2.一个activity包含多个f

    2022年11月26日
  • android 多媒体绘制之surfaceview的使用[通俗易懂]surfaceview 是android中较为特殊的视图,它继承自view,但与view不同的是它用于单独的绘画图层,平行与当前activity

  • android 布局控件之 linearlayout 和 relativelayout「建议收藏」线性布局 linearlayout 、相对布局 relativelayout 在开发中使用最多,今天就来学习下如何这两个布局的具体用法和在实际情况中如何选择这两个布局。

  • 安卓拦截app_android拦截网络请求这是我参与8月更文挑战的第4天,活动详情查看:8月更文挑战 前言 在 android 界面开发中,频繁操作是一个需要注意的点。 频繁操作: 频繁点击一个按钮,或者同时点击多个item,等产生的冲突情况

  • android motionevent事件分发介绍与流程总结(伪代码形式)如果要一句话简单总结的话,就是:找到一个按照规则“消耗”掉motionevent.action_down事件的view,默认情况下,后继会把整个事件流都交给它来处理。#.总体概括android手机是可触屏的设备,其它android设备一般也是可触屏的。可触屏设备允许用户与屏幕进行一些触碰的互动,系统识别各式各样的触摸操作,然后做出复杂的功能反应。本文一切都是针对android手机来分析说明的。用户手机触摸屏幕的那一瞬间,an…

  • 测试人必收藏系列之 android sdk[亲测有效]作为测试工程师,在日常工作测试移动端 app 的时候必定会接触到 android sdk,不管是基础的 app 功能测试,还是 app 端自动化

  • android calendar provider(日历事件)[通俗易懂]这篇文章的目的写这篇文章的目的,主要是为了记录在开发日历事件中遇到的2个比较少见,在网上比较难查找资料的问题。应用背景:在应用中通过contentprovider操作系统日历,向系统日历中添加、更新、删除日程事件。所以应用中的日程事件,是与系统日历中的事件同步的。问题1:为应用不同的登录账号添加日历账号,用此日历账号在应用中添加日程事件,然后应用切换账号,日程事件消失。问题2:删除日

发表回复

您的电子邮箱地址不会被公开。

联系金沙1005

关注“java架构师必看”公众号

回复4,添加站长微信。

附言:ispacesoft.com网而来。

关注微信
网站地图