Changing alignment (left, right etc) of SlidingDrawer handle

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 14:59:37

问题


(I've seen a few related questions but no answers so putting this out on the odd chance someone has done something similar or can point me in the right direction...)

The standard Android SlidingDrawer (and also Alessandro Crugnola's multi-direction variant which I'm using) centre-aligns the handle. Has anyone implemented a SlidingDrawer which offers the option to right or left align the handle?.. or anyone have any tips on how to go about this?


回答1:


Worked it out. In the mVertical is true condition of the onLayout(boolean changed, int l, int t, int r, int b) method of SlidingDrawer (or whatever variant of SlidingDrawer you're using), you should find the following line of code...

handleLeft = (width - childWidth) / 2;

... which centre-aligns the handle. Change this to...

handleLeft = l;

... to left-align the handle when the sliding drawer is set to slide vertical (i.e. bottom-to-top or top-to-bottom), or change it to...

handleLeft = r - handleWidth;

... to right-align the handle.

Likewise, if the sliding drawer is set to slide horizontal (i.e. right-to-left or right-to-left), in the mVertical is false condition of the onLayout(boolean changed, int l, int t, int r, int b) method, find the following line of code...

handleTop = (height - childHeight) / 2;

... and change it to...

handleTop = t;

... to top-align the handle, or...

handleTop = b - handleHeight;

... to bottom-align the handle. Happy coding!




回答2:


Assuming you are using default (vertical) orientation: If you want to move the drawer handle to the left, set the android:layout_marginRight value of the sliding drawer to some positive number. Do the opposite android:layout_marginLeft if you want the handle to move to the right. There is no align right/left per se with the sliding drawer. If you want a more dynamic alignment, you will have to use layouts to get the desired affect.



来源:https://stackoverflow.com/questions/8649545/changing-alignment-left-right-etc-of-slidingdrawer-handle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!