2012-03-18 97 views
3

我要创建一个需要从现有的用户界面的上方和单独出现,如从屏幕的底部滑动和保持锚定在那里的部件,而不管当前的内容查看。我希望它是模块化和便携的,所以预先假设一个FrameLayout是不现实的。的Android - 添加视图屏幕上,但内容视图外

在查看Dialog和PopupWindow类的源代码时,看起来他们使用Window和WindowManager类完成了这个任务,但我无法在这些类的文档中找到太多内容。

有没有简单的方法来完成我所描述的内容?

TYIA

回答

1

为了未来的搜索者的利益:答案是使用WindowManager类。这是非常简单的,尽管缺少文档(我能找到,反正):

WindowManager.LayoutParams wlp = new WindowManager.LayoutParams(); 
// assign position, dimensions, and layout behavior as properties of wlp 
WindowManager wm = (WindowManager) getSystemService("window"); 
wm.addView(someView, wlp); 
0

最简单的方法是使用RelativeLayout。将视图放置在您想要的位置,然后将可见性设置为消失。当您想要显示视图时,开始一个动画并将可见性设置为可见。

布局这样

<RelativeLayout ...> 
    <LinearLayout ...> 
    <!-- your main UI --> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/hiddenView" 
     android:visibility="gone"> 
     <!-- the UI for the separate component --> 
    </LinearLayout> 
</RelativeLayout> 

在代码

Animation someAnimation = AnimationUtils.loadAnimation(this, R.anim.some_animation); 
hiddenView.startAnimation(someAnimation); 
hiddenView.setVisibility(View.VISIBLE); 

以上是容易的,但不是非常灵活,做一些更强大的方式写在深度定制的视图或一个ViewGroup和良好不幸的是,这些教程很少。

+0

正如我所提到它必须是模块化和可移植的,所以预假设一个特定布局不起作用。我已经构建了组件,它工作正常,但我想知道如何使用Window和WindowManager类来启用功能而不考虑现有的UI。 – momo 2012-03-18 23:08:37

+0

然后,也许这个使用弹出窗口的github项目可能对你有所帮助https://github.com/lorensiuswlt/NewQuickAction/ – triggs 2012-03-18 23:39:17

+0

我会检查出来 - 谢谢 – momo 2012-03-19 00:48:46

相关问题