Changing alignment (left, right etc) of SlidingDra

2019-05-26 07:44发布

(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?

2条回答
可以哭但决不认输i
2楼-- · 2019-05-26 08:14

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.

查看更多
爷、活的狠高调
3楼-- · 2019-05-26 08:24

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!

查看更多
登录 后发表回答