Android 安卓将一个视图置于另一个视图之上
我的屏幕上有5个组件:空格、列表视图、空格、列表视图和空格,如左图所示 我希望能够在上述所有组件上方放置另一个空间(红色)。他们都躺在一条直线上 我试图在根LinearLayout中使用另一个LinearLayout(带有空格),但它只会导致bugAndroid 安卓将一个视图置于另一个视图之上,android,android-layout,android-linearlayout,Android,Android Layout,Android Linearlayout,我的屏幕上有5个组件:空格、列表视图、空格、列表视图和空格,如左图所示 我希望能够在上述所有组件上方放置另一个空间(红色)。他们都躺在一条直线上 我试图在根LinearLayout中使用另一个LinearLayout(带有空格),但它只会导致bug 根据您所拥有的,您需要一个嵌套的线性布局来容纳所有内容。它将如下所示: <LinearLayout orientation="vertical"> -- put your top container here -- -- put you
根据您所拥有的,您需要一个嵌套的线性布局来容纳所有内容。它将如下所示:
<LinearLayout orientation="vertical">
-- put your top container here --
-- put your existing linearlayout AND its contents here --
</LinearLayout>
--把你的顶部容器放在这里--
--将现有线性布局及其内容放在此处--
外部容器将是垂直的,而第二个容器将是水平的,就像您已经拥有的一样。对于您已经拥有的,您需要一个嵌套的线性布局来容纳所有内容。它将如下所示:
<LinearLayout orientation="vertical">
-- put your top container here --
-- put your existing linearlayout AND its contents here --
</LinearLayout>
Got a simple and tested layout solution right here. Refer to code below :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="#efe304"
android:orientation="vertical"
tools:context="com.example.myname.appname.NameActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ff0900"
android:paddingTop="20px" >
<Space
android:id="@+id/space1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="0.5" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20px" >
<Space
android:id="@+id/space1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#efe304"
android:layout_weight="0.5" />
<ListView
android:id="@+id/listView2"
android:layout_width="124dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#009900"
android:divider="#009900"
android:dividerHeight="10dp"
android:gravity="center"
android:scrollbars="none" />
<Space
android:id="@+id/space1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#efe304"
android:layout_weight="0.5" />
<ListView
android:id="@+id/listView2"
android:layout_width="124dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#009900"
android:divider="#009900"
android:dividerHeight="10dp"
android:gravity="center"
android:scrollbars="none" />
<Space
android:id="@+id/space1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#efe304"
android:layout_weight="0.5" />
</LinearLayout>
</LinearLayout>
--把你的顶部容器放在这里--
--将现有线性布局及其内容放在此处--
外部容器将是垂直的,而第二个容器将是水平的,就像您已经拥有的一样。这里有一个简单且经过测试的布局解决方案。请参阅下面的代码:
Got a simple and tested layout solution right here. Refer to code below :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="#efe304"
android:orientation="vertical"
tools:context="com.example.myname.appname.NameActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ff0900"
android:paddingTop="20px" >
<Space
android:id="@+id/space1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="0.5" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20px" >
<Space
android:id="@+id/space1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#efe304"
android:layout_weight="0.5" />
<ListView
android:id="@+id/listView2"
android:layout_width="124dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#009900"
android:divider="#009900"
android:dividerHeight="10dp"
android:gravity="center"
android:scrollbars="none" />
<Space
android:id="@+id/space1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#efe304"
android:layout_weight="0.5" />
<ListView
android:id="@+id/listView2"
android:layout_width="124dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#009900"
android:divider="#009900"
android:dividerHeight="10dp"
android:gravity="center"
android:scrollbars="none" />
<Space
android:id="@+id/space1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#efe304"
android:layout_weight="0.5" />
</LinearLayout>
</LinearLayout>
这里有一个简单且经过测试的布局解决方案。请参阅下面的代码:
如果不在线性布局上看到您的xmlSetandroid:orientation=“vetical”
就无法说出问题所在。因此,让您的第一个视图与父视图的宽度匹配将占用整个空间,“但这只会导致错误”…您应该解释这些“错误”是什么,以便我们能够更好地帮助您。如果您的线性布局上没有看到您的xmlSetandroid:orientation=“vetical”
,则无法说明问题所在。因此,使您的第一个视图与父视图的宽度匹配将占用整个空间,“但这只会导致错误”…您应该解释这些“错误”是什么,以便我们能够更好地帮助您。