【问题标题】:ScrollView will not make page scrollScrollView 不会使页面滚动
【发布时间】:2016-04-07 09:01:37
【问题描述】:

谁能告诉我为什么这个 ScrollView 不起作用?我检查了这个问题的其他答案,但它并没有解决我的问题。它只有一个孩子。它有一个右括号。有任何想法吗?提前致谢

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#89abe3"
    tools:context=".GardaLoginActivity" >

<RelativeLayout
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:focusableInTouchMode="true" android:fitsSystemWindows="true"
    android:background="#89abe3">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Smart Neighborhood Watch"
        android:id="@+id/Logo"
        android:textSize="40dp"
        android:layout_gravity="center_horizontal"
        android:gravity="center"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="35dp"
        android:textColor="#ffdd00"
        android:textStyle="bold"/>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/Logo"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="17dp" >

        <TextView
            android:id="@+id/lblGardaEmail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Email"
            android:textColor="#FFFFFF"/>

        </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="17dp">

        <EditText
            android:id="@+id/txtGardaEmail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:inputType="textEmailAddress"
            android:textColor="#FFFFFF"/>
        <requestFocus />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="17dp">

        <TextView
            android:id="@+id/lblGardaPassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/password"
            android:textColor="#FFFFFF"/>

        </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout3"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="17dp">

        <EditText
            android:id="@+id/txtGardaPassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColorHint="#cccccc"
            android:hint="Minimum 7 characters"
            android:inputType="textPassword"
            android:textColor="#FFFFFF" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout4"
        android:layout_centerHorizontal="true"
        android:paddingTop="30dp"
        android:gravity="center"
        android:weightSum="1">

    <Button
        android:id="@+id/btnGardaLogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/login"
        android:background="#66c2ff"
        android:textColor="#FFFFFF"
        android:layout_weight="0.30" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout5"
        android:layout_centerHorizontal="true"
        android:paddingTop="10dp"
        android:gravity="center"
        >

    <TextView
        android:id="@+id/textViewGardaRegister"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Not a member? Register"
        android:paddingTop="10dp"
        android:textColor="#FFFFFF" />
    </LinearLayout>


</RelativeLayout>

</ScrollView>

【问题讨论】:

  • 你能把 android:layout_height="wrap_content" 改成 RelativeLayout 吗??
  • @Cian 在下面看到我的答案。
  • 我试过你的代码。 Scrollview 确实对我有用。

标签: android xml android-studio scrollview


【解决方案1】:

抱歉,我写这篇文章是作为一个遮阳篷,因为我无法对问题发表评论。 如果您的布局大于屏幕,则滚动视图将起作用。

还有一件事 ScrollView's 高度 wrap_content 的子布局

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#89abe3"
        tools:context=".GardaLoginActivity" >

     <RelativeLayout
            android:layout_width="match_parent" 
            android:layout_height="wrap_content"
            android:focusableInTouchMode="true" 
            android:fitsSystemWindows="true"
            android:background="#89abe3">
           //Your Code
     </RelativeLayout>

    </ScrollView>

【讨论】:

  • 对不起。这并没有改变任何东西
【解决方案2】:

只需将您的孩子相对布局更改为

   <RelativeLayout
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:focusableInTouchMode="true"
    android:background="#89abe3">

由于相关布局android:fitsSystemWindows="true" 属性使用整个屏幕,因此 ScrollView 没有滚动空间。

【讨论】:

    【解决方案3】:

    重要提示:

    根据Android指南,android:layout_height属性的 第一个(也是唯一的)ScrollView 子项应该始终是 “包装内容”。如果你使用 match_parent,你会得到一个 Lint 警告

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       >
    

    使用此代码:

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

    【讨论】:

      【解决方案4】:
      <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="#89abe3"
          tools:context=".GardaLoginActivity" >
      
          <RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:background="#89abe3"
              android:fitsSystemWindows="true"
              android:focusableInTouchMode="true" >
      
              <TextView
                  android:id="@+id/Logo"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_centerHorizontal="true"
                  android:layout_gravity="center_horizontal"
                  android:layout_marginTop="35dp"
                  android:gravity="center"
                  android:text="Smart Neighborhood Watch"
                  android:textColor="#ffdd00"
                  android:textSize="40dp"
                  android:textStyle="bold" />
      
              <LinearLayout
                  android:id="@+id/linearLayout1"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/Logo"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <TextView
                      android:id="@+id/lblGardaEmail"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Email"
                      android:textAppearance="?android:attr/textAppearanceMedium"
                      android:textColor="#FFFFFF" />
              </LinearLayout>
      
              <LinearLayout
                  android:id="@+id/linearLayout2"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout1"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <EditText
                      android:id="@+id/txtGardaEmail"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:inputType="textEmailAddress"
                      android:textColor="#FFFFFF" />
      
                  <requestFocus />
              </LinearLayout>
      
              <LinearLayout
                  android:id="@+id/linearLayout3"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout2"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <TextView
                      android:id="@+id/lblGardaPassword"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
      
                      android:textAppearance="?android:attr/textAppearanceMedium"
                      android:textColor="#FFFFFF" />
              </LinearLayout>
      
              <LinearLayout
                  android:id="@+id/linearLayout4"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout3"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <EditText
                      android:id="@+id/txtGardaPassword"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:hint="Minimum 7 characters"
                      android:inputType="textPassword"
                      android:textColor="#FFFFFF"
                      android:textColorHint="#cccccc" />
              </LinearLayout>
      
              <LinearLayout
                  android:id="@+id/linearLayout5"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout4"
                  android:layout_centerHorizontal="true"
                  android:gravity="center"
                  android:paddingTop="30dp"
                  android:weightSum="1" >
      
                  <Button
                      android:id="@+id/btnGardaLogin"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_weight="0.30"
                      android:background="#66c2ff"
      
                      android:textColor="#FFFFFF" />
              </LinearLayout>
      
              <LinearLayout
                  android:id="@+id/linearLayout6"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout5"
                  android:layout_centerHorizontal="true"
                  android:gravity="center"
                  android:paddingTop="10dp" >
      
                  <TextView
                      android:id="@+id/textViewGardaRegister"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:paddingTop="10dp"
                      android:text="Not a member? Register"
                      android:textAppearance="?android:attr/textAppearanceMedium"
                      android:textColor="#FFFFFF" />
              </LinearLayout>
              <LinearLayout
                  android:id="@+id/linearLayout7"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout6"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <EditText
                      android:id="@+id/edt1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:hint="Minimum 7 characters"
                      android:inputType="textPassword"
                      android:textColor="#FFFFFF"
                      android:textColorHint="#cccccc" />
              </LinearLayout>
              <LinearLayout
                  android:id="@+id/linearLayout8"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout7"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <EditText
                      android:id="@+id/edt1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:hint="Minimum 7 characters"
                      android:inputType="textPassword"
                      android:textColor="#FFFFFF"
                      android:textColorHint="#cccccc" />
              </LinearLayout>
              <LinearLayout
                  android:id="@+id/linearLayout9"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout8"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <EditText
                      android:id="@+id/edt1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:hint="Minimum 7 characters"
                      android:inputType="textPassword"
                      android:textColor="#FFFFFF"
                      android:textColorHint="#cccccc" />
              </LinearLayout>
              <LinearLayout
                  android:id="@+id/linearLayout10"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout9"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <EditText
                      android:id="@+id/edt1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:hint="Minimum 7 characters"
                      android:inputType="textPassword"
                      android:textColor="#FFFFFF"
                      android:textColorHint="#cccccc" />
              </LinearLayout>
              <LinearLayout
                  android:id="@+id/linearLayout11"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout10"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <EditText
                      android:id="@+id/edt1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:hint="Minimum 7 characters"
                      android:inputType="textPassword"
                      android:textColor="#FFFFFF"
                      android:textColorHint="#cccccc" />
              </LinearLayout>
              <LinearLayout
                  android:id="@+id/linearLayout12"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout11"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <EditText
                      android:id="@+id/edt1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:hint="Minimum 7 characters"
                      android:inputType="textPassword"
                      android:textColor="#FFFFFF"
                      android:textColorHint="#cccccc" />
              </LinearLayout>
               <LinearLayout
                  android:id="@+id/linearLayout13"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout12"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <EditText
                      android:id="@+id/edt1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:hint="Minimum 7 characters"
                      android:inputType="textPassword"
                      android:textColor="#FFFFFF"
                      android:textColorHint="#cccccc" />
              </LinearLayout>
               <LinearLayout
                  android:id="@+id/linearLayout14"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout13"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <EditText
                      android:id="@+id/edt1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:hint="Minimum 7 characters"
                      android:inputType="textPassword"
                      android:textColor="#FFFFFF"
                      android:textColorHint="#cccccc" />
              </LinearLayout>
               <LinearLayout
                  android:id="@+id/linearLayout15"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout14"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <EditText
                      android:id="@+id/edt1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:hint="Minimum 7 characters"
                      android:inputType="textPassword"
                      android:textColor="#FFFFFF"
                      android:textColorHint="#cccccc" />
              </LinearLayout>
               <LinearLayout
                  android:id="@+id/linearLayout16"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout15"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <EditText
                      android:id="@+id/edt1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:hint="Minimum 7 characters"
                      android:inputType="textPassword"
                      android:textColor="#FFFFFF"
                      android:textColorHint="#cccccc" />
              </LinearLayout>
                 <LinearLayout
                  android:id="@+id/linearLayout17"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/linearLayout16"
                  android:layout_centerHorizontal="true"
                  android:layout_marginTop="17dp" >
      
                  <EditText
                      android:id="@+id/edt1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:hint="Minimum 7 characters"
                      android:inputType="textPassword"
                      android:textColor="#FFFFFF"
                       />
              </LinearLayout>
          </RelativeLayout>
      </ScrollView>
      

      【讨论】:

        【解决方案5】:

        我已经检查了您的代码。即使使用滚动,它也能完美运行。 您还有其他疑问吗?

        【讨论】:

          猜你喜欢
          • 2018-02-11
          • 1970-01-01
          • 1970-01-01
          • 2016-12-15
          • 2018-10-02
          • 2013-10-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多