在 LinearLayout 中定位元素
Positioning of elements inside a LinearLayout
我有一个问题。
在 LinearLayout 中是否可以有两个元素,一个在另一个之上?
这是我实际的 XML LinearLayout。实际上,我有一个包含元素列表 (RecyclerView) 的 LinearLayout 和一个简单的 "Open" 按钮:
<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 所建议的那样,您不能使用 LinearLayout,您必须使用 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>
我有一个问题。
在 LinearLayout 中是否可以有两个元素,一个在另一个之上?
这是我实际的 XML LinearLayout。实际上,我有一个包含元素列表 (RecyclerView) 的 LinearLayout 和一个简单的 "Open" 按钮:
<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 所建议的那样,您不能使用 LinearLayout,您必须使用 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>