ScrollView重叠的EditText在Android v4.3但不是v2.3.4中



我做了大量的研究,但这太奇怪了,我不得不发布这个问题。我有一个垂直的LinearLayout,在单行EditText上方的ScrollView上方有一个自定义视图。自定义视图的固定高度为10dp,EditText的高度为wrap_content,因此它是提示的高度。ScrollView的权重为1,因此它应该占据两者之间的所有空间。我以https://stackoverflow.com/a/7998024/852795.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
    <com.program.main.StatsBar
    android:id="@+id/mvStatsBar"
    android:layout_width="match_parent"
    android:layout_height="10dp" />     
    <ScrollView
    android:id="@+id/tvScrollMessage"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:scrollbars="vertical"
    android:fillViewport="true" >           
    <TextView
        android:id="@+id/tvMessage"
        android:textIsSelectable="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="left"
        android:textSize="14sp" />
    </ScrollView>
    <EditText android:id="@+id/command_entry"
    android:background="@drawable/command_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:lines="1"
    android:singleLine="true"
    android:textSize="16sp"
    android:hint="@string/command_entry" />
</LinearLayout>

特别奇怪的是,在我的Android v2.3.4手机上,它运行得很好——ScrollView填充文本,然后滚动,所有这些都在EditText之上。然而,在我的4.3版平板电脑上,ScrollView在EditText下重叠,因此ScrollView的最后一行总是被EditText遮住一半。对这里可能发生的事情有什么想法吗?

我已经重现了这个问题,你似乎在这个文本视图上随机添加了10dp的边距,这个视图在Android 2.3上没有显示,但在4.0上显示。

<TextView
        android:id="@+id/tvMessage"
        android:textIsSelectable="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="left"
        android:textSize="14sp" />

最新更新