简体   繁体   中英

Invoking activity when SlidingDrawer is dragged

I need to make an application with an activity consisting of a GridView and SlidingDrawer .

I have done that, but now my problem is that I need to bring an activity for half of the screen whenever the SlidingDrawer is dragged and the other half will be my previous activity and when I drag back the SlidingDrawer then the Activity should be closed.

Is this possible to handle both the activities in the screen without any conflict and if possible how should I design those activities?

You cannot put an Activity in a SlidingDrawer . You can put a View in a SlidingDrawer .

  1. The owner Activity of your SlidingDrawer should extends ActivityGroup .
  2. Get the view of the target activity, add view to SlidingDrawer 's content. Code like below:

     private void initSlidingDrawerContent() { mTestContent.removeAllViews(); //View view = LayoutInflater.from(this).inflate(R.layout.act_test, null); View view = activityToView(this, new Intent(MainActivity.this, TestActivity.class)); mTestContent.addView(view); } private View activityToView(ActivityGroup parent, Intent intent) { LocalActivityManager mLocalActivityManager = parent.getLocalActivityManager(); final Window w = mLocalActivityManager.startActivity("TagName", intent); final View wd = w != null ? w.getDecorView() : null; if (wd != null) { wd.setVisibility(View.VISIBLE); wd.setFocusableInTouchMode(true); ((ViewGroup) wd) .setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); } return wd; } 
  3. NOTE: NEVER startActivity(pkg, YourTargetActivity) ! So that the user never goes to YourTargetActivity as a stand-alone Activity .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM