android– 在其他应用程序之上带有句柄(而不是 *** 作栏)的可拖动抽屉

android– 在其他应用程序之上带有句柄(而不是 *** 作栏)的可拖动抽屉,第1张

概述背景我们都知道我们可以使用导航抽屉作为在应用程序中导航的新方法(即使使用库,如thisone).我们也知道有些应用程序可以使用SYSTEM_ALERT_WINDOWpermission漂浮在其他应用程序之上(如AirCalc所示,并且像so一样).我注意到有些应用程序结合了扩展和扩展.折叠顶部的视图,如下一个

背景

我们都知道我们可以使用导航抽屉作为在应用程序中导航的新方法(即使使用库,如this one).

我们也知道有些应用程序可以使用SYSTEM_ALERT_WINDOW permission漂浮在其他应用程序之上(如AirCalc所示,并且像so一样).

我注意到有些应用程序结合了扩展和扩展.折叠顶部的视图,如下一个:

> callerid
> Sidebar Lite
> Easy Controller-Control Center

还有很多…

问题

我们需要合并其他应用程序之上的2个概念,并允许拖动句柄以显示其左侧的内容(如导航抽屉)

也许这可以表明我的意思:

据我所知,使用系统警报权限将任何内容置于顶部需要知道视图的大小.

但是,这是不同的,因为我无法将其设置为整个屏幕,因为我不想阻止屏幕的其余部分,以防用户只看到导航抽屉的手柄.

这个问题

是否有可能合并这2个概念?

如何让所有州在表现出色的同时表现得很好?

为了避免阻止触摸,我还想让用户上下拖动手柄,或者以某种方式自定义其位置.

解决方法:

基于https://github.com/NikolaDespotoski/DrawerLayoutEdgeToggle的一些想法
我已经为NavigationDrawer实现了一个更简单的句柄版本.

使用这样:

VIEw drawer = findVIEwByID(R.ID.drawer);float verticalOffset = 0.2f;DrawerHandle.attach(drawer, R.layout.handle, verticalOffset);

DrawerHandle:

@R_419_5565@ androID.content.Context;@R_419_5565@ androID.graphics.Point;@R_419_5565@ androID.os.Build;@R_419_5565@ androID.support.v4.vIEw.GravityCompat;@R_419_5565@ androID.support.v4.vIEw.VIEwCompat;@R_419_5565@ androID.support.v4.Widget.DrawerLayout;@R_419_5565@ androID.support.v4.Widget.VIEwDragHelper;@R_419_5565@ androID.vIEw.display;@R_419_5565@ androID.vIEw.Gravity;@R_419_5565@ androID.vIEw.LayoutInflater;@R_419_5565@ androID.vIEw.MotionEvent;@R_419_5565@ androID.vIEw.VIEw;@R_419_5565@ androID.vIEw.VIEw.OnClickListener;@R_419_5565@ androID.vIEw.VIEw.OntouchListener;@R_419_5565@ androID.vIEw.VIEwGroup;@R_419_5565@ androID.vIEw.WindowManager;@R_419_5565@ androID.Widget.FrameLayout;public class DrawerHandle implements DrawerLayout.DrawerListener {    public static final String TAG = "DrawerHandle";    private VIEwGroup mRootVIEw;    private DrawerLayout mDrawerLayout;    private VIEw mHandle;    private VIEw mDrawer;    private float mVerticalOffset;    private int mGravity;    private WindowManager mWM;    private display mdisplay;    private Point mScreenDimensions = new Point();    private OnClickListener mHandleClickListener = new OnClickListener(){        @OverrIDe        public voID onClick(VIEw v) {            if(!mDrawerLayout.isDrawerOpen(mGravity)) mDrawerLayout.openDrawer(mGravity);            else mDrawerLayout.closeDrawer(mGravity);        }    };    private OntouchListener mHandletouchListener = new OntouchListener() {        private static final int MAX_CliCK_DURATION = 200;        private long startClickTime;        @OverrIDe        public boolean ontouch(VIEw v, MotionEvent event) {            switch (event.getAction()) {                case MotionEvent.ACTION_DOWN: {                    startClickTime = System.currentTimeMillis();                    break;                }                case MotionEvent.ACTION_UP: {                    if(System.currentTimeMillis() - startClickTime < MAX_CliCK_DURATION) {                        v.performClick();                        return true;                    }                }            }            MotionEvent copy = MotionEvent.obtain(event);            copy.setEdgeFlags(VIEwDragHelper.EDGE_ALL);            copy.setLocation(event.getRawX() + (mGravity == Gravity.left || mGravity == GravityCompat.START ? -mHandle.getWIDth()/2 : mHandle.getWIDth() / 2), event.getRawY());            mDrawerLayout.ontouchEvent(copy);            copy.recycle();            return true;        }    };    private int getDrawerVIEwGravity(VIEw drawerVIEw) {        final int gravity = ((DrawerLayout.LayoutParams) drawerVIEw.getLayoutParams()).gravity;        return GravityCompat.getabsoluteGravity(gravity, VIEwCompat.getLayoutDirection(drawerVIEw));    }    private float getTranslation(float slIDeOffset){        return (mGravity == GravityCompat.START || mGravity == Gravity.left) ? slIDeOffset*mDrawer.getWIDth() : -slIDeOffset*mDrawer.getWIDth();    }    private voID updateScreenDimensions() {        if (Build.VERSION.SDK_INT >= 13) {            mdisplay.getSize(mScreenDimensions);        } else {            mScreenDimensions.x = mdisplay.getWIDth();            mScreenDimensions.y = mdisplay.getHeight();        }    }    private DrawerHandle(DrawerLayout drawerLayout, VIEw drawer, int handleLayout, float handLeverticalOffset) {        mDrawer = drawer;        mGravity = getDrawerVIEwGravity(mDrawer);        mDrawerLayout = drawerLayout;        mRootVIEw = (VIEwGroup)mDrawerLayout.getRootVIEw();        LayoutInflater inflater = (LayoutInflater) mDrawerLayout.getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );        mHandle = inflater.inflate(handleLayout, mRootVIEw, false);        mWM = (WindowManager) mDrawerLayout.getContext().getSystemService(Context.WINDOW_SERVICE);        mdisplay = mWM.getDefaultdisplay();        mHandle.setonClickListener(mHandleClickListener);           mHandle.setontouchListener(mHandletouchListener);        mRootVIEw.addVIEw(mHandle, new FrameLayout.LayoutParams(mHandle.getLayoutParams().wIDth, mHandle.getLayoutParams().height, mGravity));        setVerticalOffset(handLeverticalOffset);        mDrawerLayout.setDrawerListener(this);    }    public static DrawerHandle attach(VIEw drawer, int handleLayout, float verticalOffset) {        if (!(drawer.getParent() instanceof DrawerLayout)) throw new IllegalArgumentException("Argument drawer must be direct child of a DrawerLayout");        return new DrawerHandle((DrawerLayout)drawer.getParent(), drawer, handleLayout, verticalOffset);    }    public static DrawerHandle attach(VIEw drawer, int handleLayout) {        return attach(drawer, handleLayout, 0);    }    @OverrIDe    public voID onDrawerClosed(VIEw arg0) {    }    @OverrIDe    public voID onDrawerOpened(VIEw arg0) {    }    @OverrIDe    public voID onDrawerSlIDe(VIEw arg0, float slIDeOffset) {        float translationX = getTranslation(slIDeOffset);        mHandle.setTranslationX(translationX);    }    @OverrIDe    public voID onDrawerStateChanged(int arg0) {    }    public VIEw getVIEw(){        return mHandle;    }    public VIEw getDrawer() {        return mDrawer;    }    public voID setVerticalOffset(float offset) {        updateScreenDimensions();        mVerticalOffset = offset;        mHandle.setY(mVerticalOffset*mScreenDimensions.y);    }}

布局:

<androID.support.v4.Widget.DrawerLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:ID="@+ID/drawer_layout"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent" >                <relativeLayout             androID:layout_wIDth="match_parent"            androID:layout_height="match_parent"            >            <com.fscz.vIEws.BounceVIEwPager                androID:ID="@+ID/content_pager"                androID:layout_wIDth="match_parent"                androID:layout_height="match_parent"                 androID:layout_centerInParent="true"                />            <com.fscz.vIEws.CirclePageIndicator                androID:ID="@+ID/content_indicator"                androID:layout_height="wrap_content"                androID:layout_wIDth="wrap_content"                 androID:padding="10dp"                androID:layout_centerHorizontal="true"                androID:layout_alignParentBottom="true"                androID:layout_margintop="100dp"                                />        </relativeLayout>    <linearLayout            androID:ID="@+ID/drawer"            androID:layout_wIDth="240dp"            androID:layout_height="match_parent"            androID:layout_gravity="right"            androID:orIEntation="vertical"            androID:padding="20dp"            androID:background="@color/black_transparent"            >            <TextVIEw                androID:layout_wIDth="240dp"                androID:layout_height="wrap_content"                                androID:text="@string/collections"                androID:paddingBottom="20dp"                />            <ListVIEw                 androID:ID="@+ID/drawer_List"                androID:layout_wIDth="240dp"                androID:layout_height="0dip"                androID:choiceMode="singleChoice"                androID:divIDer="@androID:color/transparent"                androID:divIDerHeight="0dp"                androID:layout_weight="1"                />    </linearLayout></androID.support.v4.Widget.DrawerLayout>

活动:

@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_browse);    mDrawerLayout = (DrawerLayout) findVIEwByID(R.ID.drawer_layout);    mDrawer = findVIEwByID(R.ID.drawer);    mDrawerList = (ListVIEw) findVIEwByID(R.ID.drawer_List);    mDrawerList.setAdapter(new ArrayAdapter<String>(this,            R.layout.drawer_List_item, Preferences.getKNownCollections()));    mDrawerList.setonItemClickListener(new AdapterVIEw.OnItemClickListener() {            @OverrIDe            public voID onItemClick(AdapterVIEw<?> adapter, VIEw vIEw, int pos, long ID) {                Preferences.setActiveCollection(Preferences.getKNownCollections()[pos]);                loader.loadAll(Preferences.getKNownCollections()[pos], browseActivity.this);                mDrawerLayout.closeDrawers();            }    });    DrawerHandle.attach(mDrawer, R.layout.handle, 0.2f);}
总结

以上是内存溢出为你收集整理的android – 在其他应用程序之上带有句柄(而不是 *** 作栏)的可拖动抽屉全部内容,希望文章能够帮你解决android – 在其他应用程序之上带有句柄(而不是 *** 作栏)的可拖动抽屉所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1100471.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存