We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.support.v7.widget.AppCompatImageView; import android.util.AttributeSet; public class ScrollImageView extends AppCompatImageView { //需要设置为 scaltype = matrix public ScrollImageView(Context context) { super(context); } public ScrollImageView(Context context, AttributeSet attrs) { super(context, attrs); } public ScrollImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } /** 加这个到addScrollListener if(contentListAdapter.getData().size()>0){ int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); for(int i=firstVisibleItemPosition;i<=lastVisibleItemPosition;i++){ View view = layoutManager.findViewByPosition(i); ScrollImageView id_content_img = view.findViewById(R.id.id_content_img); if(id_content_img!=null){ id_content_img.setDx(view.getTop(),layoutManager.getHeight()); } } } */ /** 移动距离 */ private int mDx; // layout height ~0 public void setDx(int viewTop, int layoutHeight){ if(getDrawable() ==null){ return; } int calculateHeight = getDrawable().getBounds().height() -viewHeight; if(calculateHeight<=0){ //图片太小 mDx =0; invalidate(); return; } float rate = viewTop*1.0f/layoutHeight; mDx = (int) (calculateHeight*rate); invalidate(); } private int viewHeight; @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); viewHeight = h; } @Override protected void onDraw(Canvas canvas) { Drawable drawable =getDrawable(); if(drawable==null){ super.onDraw(canvas); return; } //设置图片大小根据View的宽度 int w = getWidth(); int h = (int)(getWidth()*1.0f*drawable.getIntrinsicHeight()/drawable.getIntrinsicWidth()); drawable.setBounds(0,0,w,h); canvas.save(); canvas.translate(0,-mDx); super.onDraw(canvas); canvas.restore(); }}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: