zoukankan      html  css  js  c++  java
  • Android圆弧形ListView的实现

    本文带大家来实现ListView的圆弧形的分布排列,原理非常easy,就是依据ListView的每个Item的高度来对每个item进行偏移。

    首先自己定义一个LinearLayout,这是ListView的每一个Item的根布局,用来对每一个item进行偏移的。

    以下上代码:

    public class MatrixLinearLayout extends LinearLayout {
        private int h = 0;
        private float fullTrans = 40f;
        public MatrixView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public void setParentHeight(int height) {<pre name="code" class="java">        //传入ListView的高度
            h = height;
        }
    
        @Override
        protected void dispatchDraw(Canvas canvas) {
            canvas.save();
            int top = getTop();
            float trans = calculatetrans(top,h);
            Matrix m = canvas.getMatrix();
            m.preTranslate(-2 / getWidth(), -2 / getHeight());
            m.postTranslate(trans, 0);
            canvas.concat(m);
            super.dispatchDraw(canvas);
            canvas.restore();
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
        private float calculatetrans(int top,int h){
        	float result = 0f;
        	if(top <= h/2.349f){
        		result = (h/2f-top)/(h/7f)*fullTrans;
        	}else if(top > h/2.349f){
        		result = (top-h/3f)/(h/7f)*fullTrans;
        	}
        	return result;
        }
    }

    
    以下大家能够自己写个demo測试一下啦,就是写一个ListView,然后用上面自己定义的MatrixLinearLayout 作为ListView的item的根布局,自己动手丰衣足食!

  • 相关阅读:
    leetCode
    Autorelease Pool
    YYKit源码阅读
    读AVFoundation官方文档记录
    leetCode
    LeetCode
    图像灰度值 灰度值与像素值的关系
    CycloneII特殊管脚的使用(转)
    MOS管正确选择的步骤
    运算放大器单电源应用中的使用齐纳二极管偏置方法
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/3956048.html
Copyright © 2011-2022 走看看