我需要在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