문제

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

도움이 되었습니까?

해결책

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!

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top