1

所以我正在创建一个 android 应用程序来通过串行与 arduino 进行通信。它进展顺利,但我在布局方面遇到了一些问题。我TextView的顶部和底部都重叠,我不知道为什么!

https://www.dropbox.com/s/jaz8vbx63kd25ix/Screenshot_2012-09-27-18-53-24.png

这是我的 main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="20dp" >

    <TextView
        android:id="@+id/demoTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <ScrollView
        android:id="@+id/demoScroller"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/demoText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:typeface="monospace" />

    </ScrollView>

    <RelativeLayout
        android:id="@+id/send"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/sendButton"

        android:ems="10"
        android:hint="@string/send_text"
        android:inputType="text"
        android:singleLine="true" >
     </EditText>

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

    </RelativeLayout>

</FrameLayout>

提前致谢。

4

1 回答 1

1

这可能是因为您使用的是FrameLayout,“应该用于保存单个子视图,因为很难以一种可缩放到不同屏幕尺寸的方式组织子视图,而不会使子视图相互重叠”。尝试使用LinearLayout垂直方向的 a。

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

    <TextView
    android:id="@+id/demoTitle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />

    <!-- ... -->

    </RelativeLayout>

</LinearLayout>
于 2012-09-27T23:19:45.573 回答