android ui开发中如何实现左右滑出菜单
要让Android的应用程序中实现左右可滑出菜单只要根据以下的方法去做就可以了。对于一些熟练的开发人员来说应该是不成问题的。
public class SlidingView extends ViewGroup {
? ? ? ? private FrameLayout mContainer;
? ? ? ? private Scroller mScroller;
? ? ? ? private VelocityTracker mVelocityTracker;
? ? ? ? private int mTouchSlop;
? ? ? ? private float mLastMotionX;
? ? ? ? private float mLastMotionY;
? ? ? ? private static final int SNAP_VELOCITY = 1000;
? ? ? ? private View mLeftView;
? ? ? ? private View mRightView;
? ? ? ? public SlidingView(Context context) {
? ? ? ? ? ? ? ? super(context);
? ? ? ? ? ? ? ? init();
? ? ? ? }
? ? ? ? public SlidingView(Context context, AttributeSet attrs) {
? ? ? ? ? ? ? ? super(context, attrs);
? ? ? ? ? ? ? ? init();
? ? ? ? }
? ? ? ? public SlidingView(Context context, AttributeSet attrs, int defStyle) {
? ? ? ? ? ? ? ? super(context, attrs, defStyle);
? ? ? ? ? ? ? ? init();
? ? ? ? }
? ? ? ? @Override
? ? ? ? protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
? ? ? ? ? ? ? ? super.onMeasure(widthMeasureSpec, heightMeasureSpec);
? ? ? ? ? ? ? ? mContainer.measure(widthMeasureSpec, heightMeasureSpec);
? ? ? ? }
? ? ? ? @Override
? ? ? ? protected void onLayout(boolean changed, int l, int t, int r, int b) {
? ? ? ? ? ? ? ? final int width = r - l;
? ? ? ? ? ? ? ? final int height = b - t;
? ? ? ? ? ? ? ? mContainer.layout(0, 0, width, height);
? ? ? ? }
? ? ? ? private void init() {
? ? ? ? ? ? ? ? mContainer = new FrameLayout(getContext());
? ? ? ? ? ? ? ? mContainer.setBackgroundColor(0xff000000);
? ? ? ? ? ? ? ? mScroller = new Scroller(getContext());
? ? ? ? ? ? ? ? mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
? ? ? ? ? ? ? ? super.addView(mContainer);
? ? ? ? }
? ? ? ? public void setView(View v) {
? ? ? ? ? ? ? ? if (mContainer.getChildCount() > 0) {
? ? ? ? ? ? ? ? ? ? ? ? mContainer.removeAllViews();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? mContainer.addView(v);
? ? ? ? }
? ? ? ? @Override
? ? ? ? public void scrollTo(int x, int y) {
? ? ? ? ? ?