Android布局无法正确显示

时间:2013-09-12 21:04:47

标签: android forms layout relativelayout

这是我的代码。这只是一种形式。如果我使用我的adv(Nexus S)启动应用程序,表单显示正常,但如果我使用小屏幕,它没有完全显示(我无法向下滚动以查看表单的其余部分)。我用dip,但问题仍然存在。为什么呢?

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >

    <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello_world"
            android:layout_marginTop="15dip"
            android:layout_marginBottom="25dip"
            />

    <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/edit_name"
            />
    <EditText
            android:id="@+id/edit_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text=""
            android:hint="@string/edit_message"
            />

    <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/edit_lastname"
            android:layout_marginTop="15dip"
            />
    <EditText
            android:id="@+id/edit_lastname"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text=""
            android:hint="@string/edit_message"
            />

    <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/edit_sex"
            android:layout_marginTop="15dip"
            />
    <EditText
            android:id="@+id/edit_sex"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text=""
            android:hint="@string/edit_message"
            />

    <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/edit_age"
            android:layout_marginTop="15dip"
            />
    <EditText
            android:id="@+id/edit_age"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text=""
            android:hint="@string/edit_message"
            />

    <Button
            android:id="@+id/form_button"
            android:layout_height="wrap_content"
            android:text="@string/button_send"
            android:layout_marginTop="15dip"
            android:layout_marginLeft="90dip"
            android:layout_width="130dip"
            />

</LinearLayout>

2 个答案:

答案 0 :(得分:2)

在小屏幕上垂直显示的是Views。你可以创建一个不同的layout,它不仅仅是小屏幕的垂直,但这不是最好的方式,可能看起来不太好(实际上可能不会)

你可以将整个事物包裹在ScrollView中,这样当它不适合屏幕时就会滚动,就像屏幕较小一样。

或者您可以将Android属性用于此类型的名为android:hint的表单。您可以在TextViews中设置一个提示,告诉用户输入哪些信息,而不是使用EditText作为标签。实施例

<EditText
     android:id="@+id/edit_name"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:text=""
     android:hint="@string/edit_message"
     android:hint="Please enter name here"    <!-- see this guy here. Would want to use string resources instead of hard-coded string -->
        />

答案 1 :(得分:0)

您应该在ScrollView中包装LinearLayout。

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true" >

    <LinearLayout>
    ...
    </LinearLayout>

</ScrollView>
相关问题