Java 线性布局内元素的定位
我有个问题 在线性布局中是否可能有两个元素,一个在另一个之上 这是我实际的XML线性布局。实际上,我有一个LinearLayout,其中包含元素列表(RecyclerView)和一个简单的“打开”按钮:Java 线性布局内元素的定位,java,android,xml,kotlin,android-linearlayout,Java,Android,Xml,Kotlin,Android Linearlayout,我有个问题 在线性布局中是否可能有两个元素,一个在另一个之上 这是我实际的XML线性布局。实际上,我有一个LinearLayout,其中包含元素列表(RecyclerView)和一个简单的“打开”按钮: <LinearLayout android:id="@+id/linearbox" android:layout_width="match_parent" android:layout_height="wrap_content" android:orient
<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>
我想在我的元素列表上添加一个视图,我已经做了布局。我现在只想把它包括在我的列表中:
<include layout="@layout/open_button" />
谢谢正如Avijit Karmakar所建议的那样,你不能使用线性布局,你必须使用FrameLayout,
因为这最适合于那种您希望一个视图优于另一个视图的需求。 只需将根布局更改为FrameLayout
<FrameLayout
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" />
</FrameLayout>
在线性布局中,不能将一个视图置于另一个视图之上。为此,您必须使用FrameLayout或RelativeLayout。谢谢@AvijitKarmakar