我在android中遇到了一个奇怪的问题。我在ListView下面有一个LinearLayout。列表视图的宽度为0dp,layout_weight为90.线性布局layout_weight为10.和高度为0dp。在设备处,线性布局消失。
tab_n
我需要知道上面的问题是什么,我不想以其他方式去做。我正在做这个项目以逻辑学习,而不是复制粘贴。
这里预览设计师:
以下是设备预览:
当我打开和关闭键盘时,它会像设计师一样调整大小。我需要知道代码是否有任何错误。
编辑:来自android-dev IRC的Zharf找到了这个解决方案:
Viewpager is being pushed out of the screen [CoordinatorLayout] [Design Library]
答案 0 :(得分:0)
在ListView中使用android:layout_weight =“1”instade of android:layout_weight =“90”。还有android:layout_height =“wrap_content”instade of android:layout_height =“0dp”并且不要在LinearLayout中使用layout_weight。您可以在EditText中使用layout_weight =“1”。 希望这能解决你的问题:)
答案 1 :(得分:-1)
尝试这个...你只是在parrent线性布局中错过了一行 weightsum 。 加上这个。
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>