我的意思是,我们可以将画廊置于弯曲的路径中,图像将沿着弯曲的路径,同时它具有AndroID图库的所有属性?
如果可能,请告诉我你的想法.欢迎所有的想法.
谢谢&问候,
森
将为需要绘制的每个小孩调用drawChild.
protected boolean drawChild(Canvas canvas,VIEw child,long drawingTime) { final int left = child.getleft(); int adjustedXOrigin = left - (getWIDth() / 2) + (child.getWIDth()/2); int newtop = (int) (ellipseYOffset - Math.sqrt( ellipseMinor2 * (1 - ((Math.pow(adjustedXOrigin,2)) / ellipseMajor2)))); newtop -= (child.getHeight() / 2); if( newtop >= 0 ) { child.layout(left,newtop,left + child.getWIDth(),newtop + child.getHeight()); return super.drawChild(canvas,child,drawingTime); } return true;}
在onLayout我计算ellipseYOffset.这使得中间选择的视图在视图中垂直居中,而不管椭圆大小.
ellipseYOffset = getMeasuredHeight() + (ellipseMinor - (getMeasuredHeight() / 2));
“if(newtop> = 0)”部分是因为该视图随机地被绘制在奇怪的地方.这样就停了.
编辑:完整的代码
有一些你不需要的动画,我只是复制和粘贴我的课.
public class Carousel extends gallery {private static final float INITIAL_MInor_RATIO = 0.75f;private static final float INITIAL_MAJOR_RATIO = 1.0f;private int mEllipseMajor;private int mEllipseMinor;private int mEllipseMajor2;private int mEllipseMinor2;private int mEllipseYOffset;private Animation mgalleryAlphaOut;private Animation mgalleryAlphaIn;private OnAnimationEndListener mFadeInEndListener;private OnAnimationEndListener mFadeOutEndListener;private boolean mCustomEllipseDim = false;private boolean mInfinite = true;private int mXOff = 0;private AnimationListener mFadeInAnimationListener = new AnimationListener() { public voID onAnimationStart(Animation animation) {} public voID onAnimationRepeat(Animation animation) {} public voID onAnimationEnd(Animation animation) { if( mFadeInEndListener != null ) { mFadeInEndListener.onAnimationEnd(); } }};private AnimationListener mFadeOutAnimationListener = new AnimationListener() { public voID onAnimationStart(Animation animation) {} public voID onAnimationRepeat(Animation animation) {} public voID onAnimationEnd(Animation animation) { if( mFadeOutEndListener != null ) { mFadeOutEndListener.onAnimationEnd(); } }};public Carousel(Context context,AttributeSet attrs,int defStyle) { super(context,attrs,defStyle); init();}public Carousel(Context context,AttributeSet attrs) { super(context,attrs); init();}public Carousel(Context context) { super(context); init();}private voID init(){ setHorizontalFadingEdgeEnabled(false); setCallbackDuringFling(true); setUnselectedAlpha(1.0f); setHapticFeedbackEnabled(false); int dur = getResources().getInteger(R.integer.Transition_dur); mgalleryAlphaOut = AnimationUtils.loadAnimation(getContext(),androID.R.anim.fade_out); mgalleryAlphaOut.setFillAfter(true); mgalleryAlphaOut.setDuration(dur); mgalleryAlphaOut.setAnimationListener(mFadeOutAnimationListener); mgalleryAlphaIn = AnimationUtils.loadAnimation(getContext(),androID.R.anim.fade_in); mgalleryAlphaIn.setFillAfter(true); mgalleryAlphaIn.setDuration(dur); mgalleryAlphaIn.setAnimationListener(mFadeInAnimationListener);}public int getEllipseMajor() { return mEllipseMajor;}public voID setEllipseMajor(int ellipseMajor) { if( ellipseMajor == 0 ) { mCustomEllipseDim = false; } this.mEllipseMajor = ellipseMajor;}public int getEllipseMinor() { return mEllipseMinor;}public voID setEllipseMinor(int ellipseMinor) { if( ellipseMinor == 0 ) { mCustomEllipseDim = false; } this.mEllipseMinor = ellipseMinor;}@OverrIDeprotected boolean drawChild(Canvas canvas,long drawingTime) { final int left = child.getleft(); final int chilDWIDth = child.getWIDth(); final int childHeight = child.getHeight(); int adjustedXOrigin = left - mXOff + (chilDWIDth>>1); int newtop = (int) (mEllipseYOffset - Math.sqrt( mEllipseMinor2 * (1 - ((Math.pow(adjustedXOrigin,2)) / mEllipseMajor2)))); newtop -= (childHeight>>1); if( newtop >= 0 ) { child.layout(left,left + chilDWIDth,newtop + childHeight); return super.drawChild(canvas,drawingTime); } return true;}@OverrIDeprotected voID onLayout(boolean changed,int l,int t,int r,int b) { super.onLayout(changed,l,t,r,b); if( !mCustomEllipseDim ) { mEllipseMajor = (int) (getMeasureDWIDth() * INITIAL_MAJOR_RATIO + 0.5f); mEllipseMinor = (int) (getMeasuredHeight() * INITIAL_MInor_RATIO + 0.5f); mEllipseMajor2 = (int) Math.pow( mEllipseMajor,2 ); mEllipseMinor2 = (int) Math.pow( mEllipseMinor,2 ); } mEllipseYOffset = getMeasuredHeight() + (mEllipseMinor - (getMeasuredHeight() / 2)); mXOff = (getWIDth() / 2);}@OverrIDepublic voID setAdapter(SpinnerAdapter adapter) { super.setAdapter(adapter); if( mInfinite ) { resetposition(); }}public voID resetposition(){ int pos = Integer.MAX_VALUE / 2; if( getAdapter() != null && getAdapter().getClass() == CarouselAdapter.class ) { int size = ((CarouselAdapter)getAdapter()).getList().size(); if( size > 2 ) pos = pos - (pos % ((CarouselAdapter)getAdapter()).getList().size()); else pos = 0; setSelection(pos); }}public OnAnimationEndListener getFadeInEndListener() { return mFadeInEndListener;}public voID setFadeInEndListener(OnAnimationEndListener fadeInEndListener) { this.mFadeInEndListener = fadeInEndListener;}public OnAnimationEndListener getFadeOutEndListener() { return mFadeOutEndListener;}public voID setFadeOutEndListener(OnAnimationEndListener fadeOutEndListener) { this.mFadeOutEndListener = fadeOutEndListener;}public voID fadeIn(){ startAnimation(mgalleryAlphaIn);}public voID fadeOut(){ startAnimation(mgalleryAlphaOut);}public interface OnAnimationEndListener{ public abstract voID onAnimationEnd();}//This disables the effect of a vehicle becoming focused when it is clicked.@OverrIDepublic boolean onSingleTapUp(MotionEvent e) { if( getAdapter() != null ) { if( pointToposition((int)e.getX(),(int)e.getY()) != getSelectedItemposition() ) return true; else return super.onSingleTapUp(e); } else return true;}}总结
以上是内存溢出为你收集整理的android – 曲廊的可能性全部内容,希望文章能够帮你解决android – 曲廊的可能性所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)