2

我已经解决了我的问题。我选择了一个页眉和一个页脚,它们始终分别位于屏幕的底部和顶部。然后我创建了一个包含在 ScrollView 布局中的“中心内容”。如果人们有兴趣查看它现在的样子,我已经更新了下面的代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:background="#FFFFFF">

    <LinearLayout android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@layout/header"
        android:layout_alignParentTop="true">
        <ImageView android:src="@drawable/logo"
            android:contentDescription="@string/logo_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dip"/>
    </LinearLayout>

    <ScrollView android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="350dip"
        android:layout_below="@id/header">
        <LinearLayout android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="20dip" >
            <!--  Email Label -->
            <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#372C24"
                android:text="@string/email"/>
            <EditText android:id="@+id/email_field"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dip"
                android:singleLine="true"
                android:inputType="textEmailAddress"/>
            <!--  Password Label -->
            <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dip"
                android:textColor="#372C24"
                android:text="@string/password"/>
            <EditText android:id="@+id/password_field"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:inputType="textPassword"/>
            <!-- Login button -->
            <Button android:id="@+id/login_button"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="25dip"
                android:text="@string/login"/>
            <!-- Register button -->
            <Button android:id="@+id/register_button"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="25dip"
                android:text="@string/register_button"/>
        </LinearLayout>
    </ScrollView>

    <LinearLayout android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="90dip"
        android:background="@layout/footer"
        android:layout_alignParentBottom="true">
    </LinearLayout>

</RelativeLayout>
4

5 回答 5

5

对我来说,删除文件android:windowSoftInputMode="adjustPan"中的<activity>标签AndroidManifest.xml解决了这个问题。

于 2013-06-01T19:06:35.650 回答
1

我从 AndroidManifest.xml 文件中删除了这一行

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

并添加了这一行

android:theme="@android:style/Theme.NoTitleBar"

它既修复了我的滚动应用程序,又使我的应用程序看起来更具视觉吸引力。但是,我不确定这是否是正确的解决方法。

于 2012-12-29T05:43:57.590 回答
-1

对我来说,问题是 ScrowView 中的 LinearLayout 有 android:layout_height="wrap_content"。

<ScrollView android:id="@+id/scroll_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >

<LinearLayout android:id="@+id/layout_inside"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" --> This should not we wrap_content, but specific height.
    android:orientation="vertical" >
于 2014-01-30T14:53:09.137 回答
-2

ScrollView 在用作 XML 布局的根元素时不起作用。它必须被包裹在一个 LinearLayout 中。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ScrollView android:id="@+id/scroll_view1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true" >

    <LinearLayout android:id="@+id/layout_inside"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

玩得开心!!

于 2013-09-10T02:20:15.283 回答
-4

ScrollView 必须具有 Linearlayout 控件作为直接子级,您有相对布局,我认为这可能会导致问题。

检查这个链接,还有这个。看看他们的布局xmls ..

于 2012-12-28T22:02:38.730 回答