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
Android布局在designer中正确,但在设备中错误_Android_Xml_Layout - Fatal编程技术网

Android布局在designer中正确,但在设备中错误

Android布局在designer中正确,但在设备中错误,android,xml,layout,Android,Xml,Layout,我在安卓系统中遇到了一个奇怪的问题。我在列表视图下面有一个线性布局。列表视图的宽度为0dp,布局权重为90。线性布局重量为10。和高度0dp。在设备上,线性布局消失 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" androi

我在安卓系统中遇到了一个奇怪的问题。我在列表视图下面有一个线性布局。列表视图的宽度为0dp,布局权重为90。线性布局重量为10。和高度0dp。在设备上,线性布局消失

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ListView android:id="@+id/chatsListView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="90"
        android:divider="@null"
        android:dividerHeight="0dp"
        android:listSelector="@android:color/transparent"
        android:transcriptMode="alwaysScroll"
        />
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="10"
        android:padding="10dp">
        <EditText
            android:id="@+id/messageEditText"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:inputType="textMultiLine"
            android:hint="type message here"
            android:ems="10"/>

        <ImageButton
            android:id="@+id/sendMessageButton"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/send_button"/>

    </LinearLayout>

</LinearLayout>

我需要知道上面的问题是什么,我不想用另一种方式。我做这个项目是为了学习逻辑,而不是复制粘贴

这里是designer预览:

以下是设备中的预览:

当我打开和关闭键盘时,它会像在designer中一样调整大小。我需要知道代码是否有错误

编辑:android开发IRC的Zharf找到了此解决方案:


试试这个。。。您刚刚在parrent linear layout中错过了一行权重总和。 加上这个

android:weightSum="100"
最后的代码看起来像

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="100">

       <ListView android:id="@+id/chatsListView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="90"
        android:divider="@null"
        android:dividerHeight="0dp"
        android:listSelector="@android:color/transparent"
        android:transcriptMode="alwaysScroll"
        />

       <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="10"
        android:padding="10dp">

        <EditText
            android:id="@+id/messageEditText"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:inputType="textMultiLine"
            android:hint="type message here"
            android:ems="10"/>

        <ImageButton
            android:id="@+id/sendMessageButton"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/send_button"/>

    </LinearLayout>

</LinearLayout>

在ListView中使用android:layout\u weight=“1”安装android:layout\u weight=“90”。另外,android:layout\u height=“wrap\u content”instade的android:layout\u height=“0dp”,并且不要在线性布局中使用布局权重。您可以在EditText中使用layout_weight=“1”。
希望这能解决您的问题:)

如果您只使用PercentRelativeLayout,您可以摆脱多余的、不必要的线性布局。请尝试将
android:weightSum=“100”
添加到外部
LinearLayout
。您能在“设计器”和“实际”设备中提供设备的详细信息吗?比如设备的尺寸和设备本身(nexus、samsung等)。设备是nexus,我在designer中测试了很多设备,看起来不错。但在模拟器里,我想它只是从屏幕上消失了。我已经将父级中的weightsum设置为1,而另一个布局权重分别为0.9和0.1。同样的问题也发生了。@Slav这完全没有必要。Android自动计算权重和。我记得我以前设置过权重和,我不认为这是问题所在。在designer中,布局是正确的。将提供它的屏幕截图吗?只要提供链接我不在,一到家我就提供一个。谢谢你尝试帮助我。你确定我也在等待你的回答。我错了,weightSum没有解决问题,当我打开键盘并关闭它时,它看起来很好。逻辑在哪里?正如我所说,我需要从逻辑上知道问题出在哪里。在ListView和LinearLayout中使用layout_-weight=“90”和layout_-weight=“10”,因此它将ListView和LinearLayout分别划分为90%和10%的设备高度。因此,它在不同的设备上会表现出不同的行为。我认为你错了。在所有设备中,应遵守此规则。