Android view slides with touch
The main idea is to use the ontouch () method of the parent layout to obtain the sliding position and the clicking position, and then set the position of the child view. The edge case is considered in my code. It should be noted that relativelayout is used, taking ImageView as an example. From the test results, the performance of bottommargin and rightmargin is very poor. It is best to use leftmargin and topmargin for positioning.
The following is the operation effect:
The layout file contains a relativelayout and an ImageView. as follows
The Java code is as follows. The effect of edge position sliding is considered here. If considered, half of the ImageView will be out of the screen at the leftmost edge, and will shrink at the rightmost edge until it is invisible.
summary
The above is the Android view with touch sliding effect introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!