【问题标题】:Overlay view like YouTube app像 YouTube 应用一样的叠加视图
【发布时间】:2014-08-05 07:36:00
【问题描述】:
我正在创建一个在地图上进行一些跟踪的应用程序。跟踪部分在我的活动中非常有用。
但是,我希望在右下角有一些小的叠加层(例如 YouTube 应用中的最小化视频播放),即使我切换活动时也能保留在那里。
我查看了this,但这并不是我真正需要的。我不需要它是可移动的,我认为这在切换活动时是不可能保持的。
是否有某种可以满足我需要的类(Widget、Fragment、...)?
谢谢,
黛博R
【问题讨论】:
标签:
android
android-fragments
youtube
android-widget
overlay
【解决方案1】:
这有点晚了,可能与您不再相关,但也许其他人会觉得这很有帮助。
我认为切换活动并在屏幕上保持特定视图是不可能的。我认为应该如何做到这一点是有一个带有交换片段的主要活动,并且在活动的布局中,在片段容器的顶部有一个视图覆盖。
例如:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- Container for the fragments -->
<FrameLayout
android:id="@+id/fragment_container"
android:layout_below="@id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!-- This view will overlay the fragment in the bottom right corner -->
<View
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>