元素在LinearLayout中的位置

我有个问题。


在LinearLayout中是否可以有两个元素,一个在另一个上?


这是我实际的XML LinearLayout。实际上,我有一个LinearLayout,其中包含元素列表(RecyclerView)和一个简单的“打开”按钮:


<LinearLayout

    android:id="@+id/linearbox"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:orientation="vertical">


    <!-- Start RecyclerView -->

    <android.support.v7.widget.RecyclerView

        android:id="@+id/recyclerview"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:layout_gravity="center_horizontal" />


    <!-- Include Open Button -->

    <include layout="@layout/open_button" />


</LinearLayout>

我想在我的元素列表上添加一个View,我已经完成了布局。我现在只想将其包括在我的列表中:


<include layout="@layout/open_button" />

谢谢


qq_笑_17
浏览 220回答 1
1回答

尚方宝剑之说

正如Avijit Karmakar所建议的那样,您不能使用LinearLayout来做到这一点,您将不得不使用FrameLayout,因为它最适合您想要在一个视图之上实现另一种视图的需求。只需将您的根布局更改为FrameLayout<FrameLayout&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/linearbox"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:orientation="vertical">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <!-- Start RecyclerView -->&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <android.support.v7.widget.RecyclerView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/recyclerview"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_gravity="center_horizontal" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <!-- Include Open Button -->&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <include layout="@layout/open_button" />&nbsp; &nbsp; &nbsp; &nbsp; </FrameLayout>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java