简体   繁体   English

拖动SlidingDrawer时调用活动

[英]Invoking activity when SlidingDrawer is dragged

I need to make an application with an activity consisting of a GridView and SlidingDrawer . 我需要制作一个包含GridViewSlidingDraweractivity的应用程序。

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. 我已经做到了,但是现在我的问题是,每当拖动SlidingDrawer时,我就需要在屏幕的一半上带一个活动,另一半是我以前的activity而当我向后拖动SlidingDrawer ,应该关闭该Activity

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 . 您不能将Activity放在SlidingDrawer You can put a View in a SlidingDrawer . 您可以将View放在SlidingDrawer

  1. The owner Activity of your SlidingDrawer should extends ActivityGroup . 您的SlidingDrawer的所有者Activity应该扩展ActivityGroup
  2. Get the view of the target activity, add view to SlidingDrawer 's content. 获取目标活动的视图,将视图添加到SlidingDrawer的内容中。 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) ! 注意: 永远不要 startActivity(pkg, YourTargetActivity) So that the user never goes to YourTargetActivity as a stand-alone Activity . 这样用户就永远不会作为独立的Activity进入YourTargetActivity。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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