拖动 SlidingDrawer 时调用 Activity

发布于 2024-10-28 08:14:53 字数 330 浏览 4 评论 0原文

我需要创建一个具有由 GridViewSlidingDrawer 组成的 activity 的应用程序。

我已经做到了,但现在我的问题是,每当拖动 SlidingDrawer 时,我都需要为屏幕的一半带来一个 Activity,而另一半将是我之前的 activity当我拖回 SlidingDrawer 时,Activity 应该关闭。

是否可以在不发生任何冲突的情况下处理屏幕中的两个活动?如果可能,我应该如何设计这些活动?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

颜漓半夏 2024-11-04 08:14:53

您不能将 Activity 放入 SlidingDrawer 中。您可以将 View 放入 SlidingDrawer 中。

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

狠疯拽 2024-11-04 08:14:53
  1. SlidingDrawer 的所有者 Activity 应扩展 ActivityGroup
  2. 获取目标 Activity 的视图,将视图添加到 SlidingDrawer 的内容中。代码如下:

    private void initSlidingDrawerContent() {
        mTestContent.removeAllViews();
        //视图 view = LayoutInflater.from(this).inflate(R.layout.act_test, null);
        View view = ActivityToView(this, new Intent(MainActivity.this, TestActivity.class));
        mTestContent.addView(视图); 
    }
    
    私有视图activityToView(ActivityGroup父级,Intent意图){
        LocalActivityManager mLocalActivityManager =parent.getLocalActivityManager();
        最终窗口 w = mLocalActivityManager.startActivity("TagName",intent);
        最终视图 wd = w != null ? w.getDecorView() : null;
        如果(wd!= null){
            wd.setVisibility(View.VISIBLE);
            wd.setFocusableInTouchMode(true);
            ((ViewGroup)wd)
                    .setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
        }
        返回wd;
    }
    
  3. 注意: 决不 startActivity(pkg, YourTargetActivity)!这样用户就永远不会将 YourTargetActivity 作为独立的 Activity

  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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文