Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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
android:具有垂直线性布局的布局重量_Android_Xml_Layout - Fatal编程技术网

android:具有垂直线性布局的布局重量

android:具有垂直线性布局的布局重量,android,xml,layout,Android,Xml,Layout,我正在尝试创建一个android布局,如: [######编辑文本###][按钮] [#####列表视图#### 为此,我使用了权重,但下面的xml给了我一些非常奇怪的东西,比如: [编辑文本][按钮][列表视图] 有人知道为什么吗 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:

我正在尝试创建一个android布局,如:

[######编辑文本###][按钮]

[#####列表视图####

为此,我使用了权重,但下面的xml给了我一些非常奇怪的东西,比如:

[编辑文本][按钮][列表视图]

有人知道为什么吗

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/background"
    android:weightSum="10"
     >

    <EditText android:id="@+id/nova_lista"
        android:inputType="text"
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_weight="9"
        android:hint="@string/new_list_hint">

    </EditText>

    <Button android:id="@+id/nova_lista_botao"
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:text="@string/new_list"/>

    <ListView
        android:id="@+id/list_of_lists"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

您正在使用的是
android:orientation=“vertical”

您正在指定
android:layou width
等于
0dp

对于垂直
布局,如果在线性布局中使用
重量
,则高度
应为
0 dp
;对于水平布局,宽度应为0 dp

编辑文本
按钮
放在单独的
水平布局中。使用下面的代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/background"
     >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="10"
     >

    <EditText android:id="@+id/nova_lista"
        android:inputType="text"
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_weight="9"
        android:hint="@string/new_list_hint">

    </EditText>

    <Button android:id="@+id/nova_lista_botao"
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:text="@string/new_list"/>
</LinearLayout>
    <ListView
        android:id="@+id/list_of_lists"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

您正在使用的是
android:orientation=“vertical”

您正在指定
android:layou width
等于
0dp

对于垂直
布局,如果在线性布局中使用
重量
,则高度
应为
0 dp
;对于水平
布局,宽度应为0 dp

编辑文本
按钮
放在单独的
水平布局中。使用下面的代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/background"
     >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="10"
     >

    <EditText android:id="@+id/nova_lista"
        android:inputType="text"
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_weight="9"
        android:hint="@string/new_list_hint">

    </EditText>

    <Button android:id="@+id/nova_lista_botao"
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:text="@string/new_list"/>
</LinearLayout>
    <ListView
        android:id="@+id/list_of_lists"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

也许这就是你要找的:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#ffffff" >    


    <EditText 
        android:id="@+id/nova_lista"       
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" 
        android:layout_toLeftOf="@id/nova_lista_botao"
        android:inputType="text"       
        android:hint="something">

    </EditText>

    <Button 
        android:id="@+id/nova_lista_botao"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Hello"/>

    <ListView
        android:id="@+id/list_of_lists"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/nova_lista" >
    </ListView>

</RelativeLayout>


希望这能有所帮助。

也许这就是你想要的:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#ffffff" >    


    <EditText 
        android:id="@+id/nova_lista"       
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" 
        android:layout_toLeftOf="@id/nova_lista_botao"
        android:inputType="text"       
        android:hint="something">

    </EditText>

    <Button 
        android:id="@+id/nova_lista_botao"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Hello"/>

    <ListView
        android:id="@+id/list_of_lists"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/nova_lista" >
    </ListView>

</RelativeLayout>


希望对你有所帮助。

1.设置你的主布局是相对的

2.创建LinerLayout并将EditText和按钮移动到LinerLayout

3.设置LinerLayout为“@+id/top_布局”,设置listview为

android:layout_below=“@+id/top_layout”


1.将主布局设置为相对布局

2.创建LinerLayout并将EditText和按钮移动到LinerLayout

3.设置LinerLayout为“@+id/top_布局”,设置listview为

android:layout_below=“@+id/top_layout”