2012-12-28 107 views
2

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

回答

1

我删除从AndroidManifest.xml中此行的文件

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

,并加入这一行

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

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

-4

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

检查this链接了,也this。看看他们的布局个XML ..

+5

其实并非如此。您可以在scrollview中拥有任何但只有一个孩子 – wtsang02

+2

Scroll视图不需要将LinearLayout作为其直接子对象。 http://developer.android.com/reference/android/widget/ScrollView.html –

5

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

+0

这解决了我的问题:)谢谢! –

+0

我想知道如果我想要使用上面的属性,替代方案是什么! – Skynet

-3

当用作XML布局的根元素时,ScrollView不起作用。 它必须包装在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" > 

玩得开心! !

-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" > 
+1

根据Android的指导原则,第一个(也是唯一的)ScrollView子代的'android:layout_height'属性应该总是“'wrap_content'”。如果你使用match_parent,你会得到一个Lint警告。 – chteuchteu