Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 类Applauze列表视图_Android_Android Listview_Android Custom View - Fatal编程技术网

Android 类Applauze列表视图

Android 类Applauze列表视图,android,android-listview,android-custom-view,Android,Android Listview,Android Custom View,我正在尝试制作一个像ios应用程序Applauze中那样的自定义列表视图 我扩展了listview类,并在onTouchEvent的帮助下尝试检测子行的移动,并在移动时更改它们的高度。因此,与其他行相比,最上面的子行具有最大的高度 public class CustView extends ListView{ private float mLastTouchY; private int mActivePointerId; private boolean up=fal

我正在尝试制作一个像ios应用程序Applauze中那样的自定义列表视图

我扩展了listview类,并在onTouchEvent的帮助下尝试检测子行的移动,并在移动时更改它们的高度。因此,与其他行相比,最上面的子行具有最大的高度

  public class CustView extends ListView{

    private float mLastTouchY;
    private int mActivePointerId;
    private boolean up=false;
    private boolean down=false;
    private final Camera mCamera = new Camera();
    private final Matrix mMatrix = new Matrix();
    private Context context;
    private Paint mPaint;


    public CustView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        this.setChildrenDrawingOrderEnabled(true);
    }   
    public CustView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
    }

    @Override
    protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
        // get top left coordinates
        boolean isTop = false;
        final int top = child.getTop();
        final int bottom = child.getBottom();
        child.setMinimumHeight(getHeight()/3);
        Bitmap bitmap = child.getDrawingCache();
        Bitmap cropBitmap;
        if (bitmap == null) {
            child.setDrawingCacheEnabled(true);
            child.buildDrawingCache();
            bitmap = child.getDrawingCache();
        }
        int belowE = (child.getHeight()*2/3)+getPaddingTop();
        int aboveE = (child.getHeight())+getPaddingTop();
        mCamera.save();
        if(up){
            if (top>=belowE) {
                //make all small
                isTop = true;
                //canvas.scale(1.0f, 0.5f);
                cropBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight()/2);
                child.setMinimumHeight(2);
                //child.setLayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                child.setPressed(true);
                Log.e("Chota", child.getMeasuredHeight()+"True"+top);
            }  
            else {
                //canvas.scale(1.0f,xy);
                cropBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight());
                //child.setLayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                //child.setMinimumHeight(4);
                Log.e("Bada", child.getMeasuredHeight()+"False"+top);
                child.setPressed(false);
            };
        }
        else{
            if (bottom>aboveE) {
                //make center row bigger
                isTop = true;
                //canvas.scale(1.0f, 0.5f);
                cropBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight()/2);
                child.setMinimumHeight(2);
                child.setPressed(true);
                Log.e("Bada", child.getMeasuredHeight()+"True"+top);
            }  
            else {
                //canvas.scale(1.0f,xy);
                cropBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight());
                //child.setMinimumHeight(getHeight()/4);
                Log.e("Chota", child.getMeasuredHeight()+"False"+top);
                child.setPressed(false);
            };
        }

            mCamera.getMatrix(mMatrix);
        mCamera.restore();

        // create and initialize the paint object
        if (mPaint == null) {
            mPaint = new Paint();
            mPaint.setAntiAlias(true);
            mPaint.setFilterBitmap(true);
        }
        mMatrix.postScale(1.0f, 1.5f);
        mMatrix.postTranslate(child.getLeft(), top);
        canvas.drawBitmap(cropBitmap, mMatrix, mPaint);
        //Log.e("Up", "Child"+top+" "+getTop());
        return false;
    }



    /* (non-Javadoc)
     * @see android.widget.AbsListView#onTouchEvent(android.view.MotionEvent)
     */
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        // TODO Auto-generated method stub
        final int action = MotionEventCompat.getActionMasked(ev); 

        int INVALID_POINTER_ID=65421385;
        switch (action) { 
        case MotionEvent.ACTION_DOWN: {
            final int pointerIndex = MotionEventCompat.getActionIndex(ev); 
            // Remember where we started (for dragging)
            mLastTouchY = MotionEventCompat.getY(ev, pointerIndex);
            // Save the ID of this pointer (for dragging)
            mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
            Log.e("Down", "Down");
            break;
        }

        case MotionEvent.ACTION_MOVE: {
            // Find the index of the active pointer and fetch its position
            final int pointerIndex = 
                    MotionEventCompat.findPointerIndex(ev, mActivePointerId);  
            final float y = MotionEventCompat.getY(ev, pointerIndex);

            // Calculate the distance moved
            final float dy = y - mLastTouchY;

            up = dy<0;
            down = dy>0;

            //((MyAdapter)getListAdapter()).animate(fVI,top,bottom,getChildCount());
            if(Math.abs(dy)>10){
                Log.e("Dist", "D-"+Math.abs(dy));
                invalidate();
            }

            // Remember this touch position for the next move event
            mLastTouchY = y;
            Log.e("Move", "Move");
            break;
        }

        case MotionEvent.ACTION_UP: {
            mActivePointerId = INVALID_POINTER_ID;
            Log.e("Up", "Up");
            break;
        }

        case MotionEvent.ACTION_CANCEL: {
            mActivePointerId = INVALID_POINTER_ID;
            break;
        }

        case MotionEvent.ACTION_POINTER_UP: {

            final int pointerIndex = MotionEventCompat.getActionIndex(ev); 
            final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); 

            if (pointerId == mActivePointerId) {
                // This was our active pointer going up. Choose a new
                // active pointer and adjust accordingly.
                final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                mLastTouchY = MotionEventCompat.getY(ev, newPointerIndex); 
                mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
            }
            break;
        }
        }
        return super.onTouchEvent(ev);
    }

    /* (non-Javadoc)
     * @see android.view.View#onScrollChanged(int, int, int, int)
     */
    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        // TODO Auto-generated method stub
        super.onScrollChanged(l, t, oldl, oldt);
    }
}
公共类CustView扩展了ListView{
私密的浮躁和敏感;
私有int-mActivePointerId;
private boolean up=false;
私有布尔向下=false;
专用最终摄像头mCamera=新摄像头();
私有最终矩阵mMatrix=新矩阵();
私人语境;
私人油漆;
公共客户视图(上下文、属性集属性){
超级(上下文,attrs);
this.context=上下文;
此.setChildrenDrawingOrderEnabled(true);
}   
公共CustView(上下文上下文、属性集属性、int defStyle){
超级(上下文、属性、定义样式);
//TODO自动生成的构造函数存根
}
@凌驾
受保护的布尔drawChild(画布、视图子对象、长drawingTime){
//获取左上角的坐标
布尔isTop=false;
final int top=child.getTop();
final int bottom=child.getBottom();
setMinimumHeight(getHeight()/3);
位图位图=child.getDrawingCache();
位图cropBitmap;
如果(位图==null){
setDrawingCacheEnabled(true);
buildDrawingCache();
位图=child.getDrawingCache();
}
int belowE=(child.getHeight()*2/3)+getPaddingTop();
intovere=(child.getHeight())+getPaddingTop();
mCamera.save();
如果(向上){
如果(顶部>=下方){
//小打小闹
isTop=真;
//画布比例(1.0f,0.5f);
cropBitmap=Bitmap.createBitmap(位图,0,0,Bitmap.getWidth(),Bitmap.getHeight()/2);
儿童。设置最低身高(2);
//setLayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
child.setPressed(true);
Log.e(“Chota”,child.getMeasuredHeight()+“True”+top);
}  
否则{
//画布比例(1.0f,xy);
cropBitmap=Bitmap.createBitmap(Bitmap,0,0,Bitmap.getWidth(),Bitmap.getHeight());
//setLayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
//儿童。设置最低身高(4);
Log.e(“Bada”,child.getMeasuredHeight()+“False”+top);
child.setPressed(false);
};
}
否则{
如果(底部>上方){
//使中心行变大
isTop=真;
//画布比例(1.0f,0.5f);
cropBitmap=Bitmap.createBitmap(位图,0,0,Bitmap.getWidth(),Bitmap.getHeight()/2);
儿童。设置最低身高(2);
child.setPressed(true);
Log.e(“Bada”,child.getMeasuredHeight()+“True”+top);
}  
否则{
//画布比例(1.0f,xy);
cropBitmap=Bitmap.createBitmap(Bitmap,0,0,Bitmap.getWidth(),Bitmap.getHeight());
//setMinimumHeight(getHeight()/4);
Log.e(“Chota”,child.getMeasuredHeight()+“False”+top);
child.setPressed(false);
};
}
mCamera.getMatrix(mMatrix);
mCamera.restore();
//创建并初始化绘制对象
if(mPaint==null){
mPaint=新油漆();
mPaint.setAntiAlias(true);
mPaint.setFilterBitmap(true);
}
mMatrix.后标度(1.0f,1.5f);
mMatrix.postTranslate(child.getLeft(),顶部);
画布.绘图位图(cropBitmap、mMatrix、mPaint);
//Log.e(“Up”、“Child”+top+“”+getTop());
返回false;
}
/*(非Javadoc)
*@see android.widget.AbsListView#onTouchEvent(android.view.MotionEvent)
*/
@凌驾
公共事件(MotionEvent ev){
//TODO自动生成的方法存根
final int action=MotionEventCompat.getActionMasked(ev);
int无效_指针_ID=65421385;
开关(动作){
case MotionEvent.ACTION\u DOWN:{
final int pointerIndex=MotionEventCompat.getActionIndex(ev);
//记住我们从哪里开始(拖动)
mLastTouchY=MotionEventCompat.getY(ev,pointerIndex);
//保存此指针的ID(用于拖动)
MacTivePointId=MotionEventCompat.getPointerId(ev,0);
Log.e(“向下”、“向下”);
打破
}
case MotionEvent.ACTION\u移动:{
//查找活动指针的索引并获取其位置
最终整数指针索引=
MotionEventCompat.findPointerIndex(ev,MacTivePointId);
最终浮点y=MotionEventCompat.getY(ev,pointerIndex);
//计算移动的距离
最终浮子dy=y—最大浮子厚度;
up=dy0;
//((MyAdapter)getListAdapter())。设置动画(fVI、顶部、底部、getChildCount());
如果(数学绝对值(dy)>10){
Log.e(“Dist”,“D-”+Math.abs(dy));
使无效();
}
//记住下一个移动事件的触摸位置
mLastTouchY=y;
Log.e(“移动”、“移动”);
打破
}
case MotionEvent.ACTION\u UP:{
MacTivePointId=无效的\u指针\u ID;
Log.e(“向上”、“向上”);
打破
}
case MotionEvent.ACTION\u取消:{
MacTivePointId=无效的\u指针\u ID;
打破
}
case MotionEvent.ACTION\u指针\u向上:{
final int pointerIndex=MotionEventCompat.getActionIndex(ev);
final int pointerId=MotionEventCompat.getPointerId(ev,pointerIndex);