我需要在RelativeLayout内移动一个ImageView(或其他任何东西)。有没有人知道这样做的正确方法?在RelativeLayout中移动ImageView
6
A
回答
10
Makesure ImageView的的layout_height和layout_width设置为FILL_PARENT。然后做:
要移动视图,使用矩阵。这非常方便。
Matrix matrix = new Matrix();
matrix.reset();
matrix.postTranslate(x, y);
imageview.setScaleType(ScaleType.MATRIX);
imageview.setImageMatrix(matrix);
+0
记得在xml中设置ImageView android:scaleType =“matrix”,如果你打算使用它并将视图返回到中心/开始位置(如操纵杆手柄),否则如果没有设置它将得到偏移量。 – TouchBoarder
1
0
这很容易。你可以实现你想要的任何控件的onTouchListener
事件,并设置它的x,y位置,如创建一个新的LayoutParams
设置它的x,y并指定查看为view.setLayoutParam(layoutParams);
它将拖动视图。
2
这个我发现工作:
imageview.layout(l,t,r,b);
相关问题
- 1. 在RelativeLayout中动画ImageView
- 2. 将imageview从scrollview移动到relativelayout
- 3. 在RelativeLayout中移动android
- 4. 的ImageView在RelativeLayout的
- 5. 在relativelayout中动态地移动视图
- 6. 当移动RelativeLayout(Android)时,ImageView的大小略有增加
- 7. ImageView到RelativeLayout的中间 - Android
- 8. 在RelativeLayout中垂直TextView的中心ImageView
- 9. RelativeLayout与ImageView和TextView
- 10. Android,RelativeLayout在同一RelativeLayout中更改ImageView时重新启动Marquee-TextView
- 11. 在RelativeLayout中显示/隐藏ImageView
- 12. 在RelativeLayout中使用ImageView重复图像
- 13. 如何在RelativeLayout中显示某些ImageView?
- 14. 动态添加ImageView到RelativeLayout:不可见
- 15. Android移动ImageView
- 16. 使用ImageView在RelativeLayout中隐藏/显示另一个ImageView
- 17. 在imageview上移动形状?
- 18. 在ImageView上移动TextView?
- 19. Android RelativeLayout不移动项目
- 20. RelativeLayout边距缩小ImageView
- 21. 移动图像imageview
- 22. 平稳移动imageview
- 23. 移动imageview顶部
- 24. 在XML中移动imageview导致崩溃
- 25. RelativeLayout中的ImageView与父项不匹配
- 26. 如何在Android上显示RelativeLayout和ImageView?
- 27. 在RelativeLayout ImageView不需要的边框
- 28. 的Android ImageView的圈放置在RelativeLayout的
- 29. Android imageview在限制内移动拖动
- 30. Android - 如何移动ImageView在滑动
你能成为一个更具体一点? “移动”是什么意思? – CommonsWare
像,移动它的x \ y坐标。例如,如果您的图像大于屏幕分辨率,并且希望能够拖动它以查看屏幕外的部分。 – Joren