<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.85"
android:orientation="horizontal" android:layout_marginTop="10px">
<EditText
android:id="@+id/editText1"
android:layout_width="299dp"
android:layout_height="wrap_content"
android:layout_weight="1" android:lines="1"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="clear" />
</LinearLayout>
<ListView
android:id="@+id/mylist"
android:layout_height="413dp"
android:layout_weight="0.52" android:layout_width="fill_parent">
</ListView>
</LinearLayout>
这种布局有什么问题?
1) 当我以纵向模式打开应用程序时,这个 TextEdit 是可见的,直到我单击它以输入一些文本(只有黑色)。如果我把它变成横向模式,textedit 会再次出现(在全屏模式下)
2) 当我以横向模式打开应用程序时,只有布局标题和下面的黑色再次出现。
看起来并不太复杂.. 这是伪 xml:
<row>
<col. for text>
<col. for button>
</row>
<row>
<some text here>
</row>
你能帮我修复这个布局或者给我一些更好的例子吗?
最佳答案
您有一个高度为 413dp(相当大)的 ListView 。我认为您误解了 layout_weight 决定如何分配多余空间,考虑到您的 ListView 太大,其中不会有太多空间。
您可能想要的是将水平线性布局设置为没有 layout_weight 并告诉 ListView 全部使用它:
<ListView
android:id="@+id/mylist"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="fill_parent"
>
</ListView>
关于android - TextEdit 在键盘上消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9343640/