Move ImageView around inside RelativeLayout

前端 未结 4 455
孤城傲影
孤城傲影 2020-12-10 17:00

I need to move an ImageView (or anything else, for that matter) around inside a RelativeLayout. Does any one know the proper way to do this?

相关标签:
4条回答
  • 2020-12-10 17:07

    mImageView.scrollBy(xOffset, yOffset);

    0 讨论(0)
  • 2020-12-10 17:10

    Makesure ImageView's layout_height and layout_width is set to fill_parent. Then do:

    To move a view, use Matrix. It is very handy.

    Matrix matrix = new Matrix();
    
    matrix.reset();
    
    matrix.postTranslate(x, y);
    
    imageview.setScaleType(ScaleType.MATRIX);
    imageview.setImageMatrix(matrix);
    
    0 讨论(0)
  • 2020-12-10 17:11

    It is very easy. You can implement onTouchListener event of any control you want and set its x, y position like make a new LayoutParams set its x, y and assign to view as view.setLayoutParam(layoutParams); it will drag the View.

    0 讨论(0)
  • 2020-12-10 17:26

    this I found worked:

    imageview.layout(l,t,r,b);
    
    0 讨论(0)
提交回复
热议问题