Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何实现在MainActivity中始终可见并固定在所有片段之上的视图?_Java_Android_Android Activity_View_Fragment - Fatal编程技术网

Java 如何实现在MainActivity中始终可见并固定在所有片段之上的视图?

Java 如何实现在MainActivity中始终可见并固定在所有片段之上的视图?,java,android,android-activity,view,fragment,Java,Android,Android Activity,View,Fragment,如何实现在MainActivity中始终可见并固定在所有片段之上的视图? 在替换片段时,我也需要这样做,而不仅仅是在添加片段时。您可以在activity\u main.xml中尝试以下操作: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="matc

如何实现在MainActivity中始终可见并固定在所有片段之上的视图?
在替换片段时,我也需要这样做,而不仅仅是在添加片段时。

您可以在activity\u main.xml中尝试以下操作:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:orientation:vertical>

<!-- Your View above the fragment, f.e. an ImageView -->
<ImageView
    android:id="@+id/icon_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher"
    android:contentDescription="@string/empty" />

<!-- Your fragment container -->
<FrameLayout
    android:id="@+id/fragmentContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
</FrameLayout> </LinearLayout>

这应该能奏效。只需将ImageView替换为要放置在片段上方的另一个视图。

您所询问的信息非常模糊。此外,您还应该首先学习android活动的基础知识,它如何显示视图,以及片段如何与活动一起使用。