如何在ScrollView中设置uo onScale自定义视图

时间:2018-10-11 15:15:53

标签: android android-recyclerview

我有一个带有自定义视图的RecyclerView。我想重新缩放自定义视图。为此,我实现了onScale并将其添加到onTouchEvent中。

@Override
public boolean onTouchEvent(MotionEvent event) {
    scaleDetector.onTouchEvent(event);
    return true;
}

private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
    @Override
    public boolean onScale(ScaleGestureDetector detector) {
        Log.d(TAG, "Scale factor: " + detector.getScaleFactor());
        invalidate();
        return true;
    }
}

但是当我开始进行zomming时,我的logcat几乎没有得到任何比例因子(在一些我无法确定的罕见情况下,我得到了它。我认为RecyclerView中的问题有自己的缺点。侦听器,并且它们彼此同意。如何调整我的自定义视图?

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
    List<ChartDefiner> chartDefiners;

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        ChartView chartView;

        public MyViewHolder(ChartView chartView) {
            super(chartView);
            this.chartView = chartView;
        }
    }

    public MyAdapter(List<ChartDefiner> chartDefiners) {
        this.chartDefiners = chartDefiners;
    }

    @Override
    public MyAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ChartView v = (ChartView) LayoutInflater.from(parent.getContext()).inflate(R.layout.chart_layout, parent, false);
        return new MyViewHolder(v);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        ChartDefiner chartDefiner = chartDefiners.get(position);
        holder.chartView.setForecasts(chartDefiner.getForecasts());
        holder.chartView.setMeasurements(chartDefiner.getMeasurements());
        holder.chartView.setMedications(chartDefiner.getMedications());
    }


    @Override
    public int getItemCount() {
        return 1;
    }
}

0 个答案:

没有答案