【问题标题】:Scrolling not working in android xml layout?滚动在android xml布局中不起作用?
【发布时间】:2016-12-26 06:22:41
【问题描述】:

让这个布局滚动它不是滚动的,我遇到了问题。我也在这个中使用了 Scrollview。我无法检测到它为什么不起作用。这是一个登录屏幕,屏幕底部有社交登录按钮。但它不工作。

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mail_login"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/login_bg_img"
android:isScrollContainer="true">


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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:isScrollContainer="true">

        <TextView
            android:id="@+id/txt_heading"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="15dp"
            android:background="@null"
            android:gravity="center"
            android:text="Sign In"
            android:textColor="#ffffff"
            android:textSize="@dimen/Login_signinText" />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="55dp"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="30dp"

                    android:src="@mipmap/login_logo_icon" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center"

                android:gravity="center"
                android:orientation="vertical">

                <LinearLayout

                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:background="@mipmap/login_input_bar1"
                        android:gravity="left|center_vertical"
                        android:orientation="vertical">

                        <EditText
                            android:id="@+id/et_email_login"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:background="@null"
                            android:hint="Username"

                            android:maxLength="20"
                            android:maxLines="1"
                            android:paddingLeft="10dp"
                            android:paddingRight="10dp"
                            android:singleLine="true"
                            android:textColor="#777e86"
                            android:textColorHint="#777e86"
                            android:textSize="@dimen/Login_username" />


                    </LinearLayout>

                </LinearLayout>

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

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:background="@mipmap/login_input_bar2"
                        android:gravity="left|center_vertical"

                        android:orientation="vertical">

                        <EditText
                            android:id="@+id/et_password_login"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:background="@null"
                            android:hint="Password"
                            android:inputType="textPassword"

                            android:maxLength="15"
                            android:maxLines="1"


                            android:paddingLeft="10dp"
                            android:paddingRight="10dp"
                            android:singleLine="true"
                            android:textColor="#777e86"
                            android:textColorHint="#777e86"
                            android:textSize="@dimen/Login_username" />


                    </LinearLayout>


                    <TextView
                        android:id="@+id/txt_forget_password"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="4dp"
                        android:layout_marginTop="5dp"
                        android:text="Forgot Password?"
                        android:textColor="#ffffff"
                        android:textSize="@dimen/Login_forgotpassword" />

                    <TextView
                        android:id="@+id/txt_sign_up"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="4dp"
                        android:layout_marginTop="30dp"
                        android:gravity="center"
                        android:text="Forget Password"
                        android:textColor="#ffffff"
                        android:textSize="@dimen/Login_forgotpassword" />

                </LinearLayout>


                <RelativeLayout

                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="15dp"
                    android:gravity="center"
                    android:orientation="vertical">

                    <ImageView
                        android:id="@+id/login_btn"
                        style="?android:borderlessButtonStyle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/login_btn" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_centerVertical="true"
                        android:text="Let me in"
                        android:textColor="#fff"
                        android:textSize="18sp" />
                </RelativeLayout>

                <!--<LinearLayout-->
                <!--android:layout_width="match_parent"-->
                <!--android:layout_height="wrap_content"-->
                <!--android:orientation="vertical"-->
                <!--android:gravity="center"-->
                <!--android:layout_marginTop="15dp"-->
                <!--android:paddingBottom="10dp"-->
                <!--android:layout_alignParentBottom="true">-->

                <!--<TextView-->
                <!--android:id="@+id/forgot_login"-->
                <!--android:layout_width="wrap_content"-->
                <!--android:layout_height="wrap_content"-->
                <!--android:paddingBottom="8dp"-->
                <!--android:paddingRight="5dp"-->
                <!--android:text="Forgot Password ?"-->
                <!--android:textSize="18sp"-->
                <!--android:textColor="#fff"/>-->
                <!--</LinearLayout>-->

                <!--<LinearLayout-->
                <!--android:layout_width="match_parent"-->
                <!--android:layout_height="wrap_content"-->
                <!--android:orientation="vertical"-->
                <!--android:gravity="center"-->
                <!--android:layout_marginTop="25dp"-->
                <!--android:paddingBottom="10dp"-->
                <!--android:layout_alignParentBottom="true">-->

                <!--<TextView-->
                <!--android:id="@+id/Sign_up"-->
                <!--android:layout_width="wrap_content"-->
                <!--android:layout_height="wrap_content"-->
                <!--android:paddingBottom="8dp"-->
                <!--android:paddingRight="5dp"-->
                <!--android:text="Don't have an account? Sign Up"-->
                <!--android:textSize="18sp"-->
                <!--android:textColor="#fff"/>-->
                <!--</LinearLayout>-->

            </LinearLayout>


        </LinearLayout>


    </LinearLayout>
</ScrollView>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginTop="30dp"
    android:orientation="horizontal"
    android:weightSum="3">


    <LinearLayout
        android:id="@+id/ll_fb"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@mipmap/login_facebook_btn"
        android:orientation="horizontal">


    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_google"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@mipmap/login_google_btn"
        android:orientation="horizontal">


    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_twitter"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@mipmap/login_twitter_btn"
        android:orientation="horizontal">


    </LinearLayout>


</LinearLayout>

【问题讨论】:

  • 因为你的scrollview的高度是wrap_content...请把它改成fill_parent/match_parent

标签: android xml layout scrollview android-linearlayout


【解决方案1】:

试着像那样工作

 <ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/llbottom"
    android:layout_alignParentTop="true"
    >

并将 id 带到你的底部 id

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginTop="30dp"
    android:orientation="horizontal"
    android:id="@+id/llbottom"
    android:weightSum="3">

【讨论】:

  • 移除主Container Top Relavtive布局中的android:isScrollContainer="true"...
  • 为什么你在每个中都使用 android:isScrollContainer="true"...删除它...然后尝试
【解决方案2】:

在最后关闭标签。&lt;/RelativeLayout&gt;

【讨论】:

    【解决方案3】:

    尝试将此属性添加到您的滚动查看器:

    android:fillViewport="true"
    

    【讨论】:

      【解决方案4】:

      你用这个。`

      <?xml version="1.0" encoding="utf-8"?>
      
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/mail_login"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@mipmap/ic_launcher"
      >
      
      
      <ScrollView
          android:layout_width="match_parent"
          android:layout_height="120dp"
          >
      
          <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:isScrollContainer="true">
      
              <TextView
                  android:id="@+id/txt_heading"
                  android:layout_width="match_parent"
                  android:layout_height="50dp"
                  android:layout_marginTop="15dp"
                  android:background="@null"
                  android:gravity="center"
                  android:text="Sign In"
                  android:textColor="#ffffff"
                  android:textSize="12sp" />
      
      
              <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical">
      
                  <LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginTop="55dp"
                      android:orientation="vertical">
      
                      <ImageView
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_gravity="center"
                          android:layout_marginTop="30dp"
      
                          android:src="@mipmap/ic_launcher" />
                  </LinearLayout>
      
                  <LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:layout_gravity="center"
      
                      android:gravity="center"
                      android:orientation="vertical">
      
                      <LinearLayout
      
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:orientation="vertical">
      
                          <LinearLayout
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_gravity="center"
                              android:background="@mipmap/ic_launcher"
                              android:gravity="left|center_vertical"
                              android:orientation="vertical">
      
                              <EditText
                                  android:id="@+id/et_email_login"
                                  android:layout_width="match_parent"
                                  android:layout_height="wrap_content"
                                  android:background="@null"
                                  android:hint="Username"
      
                                  android:maxLength="20"
                                  android:maxLines="1"
                                  android:paddingLeft="10dp"
                                  android:paddingRight="10dp"
                                  android:singleLine="true"
                                  android:textColor="#777e86"
                                  android:textColorHint="#777e86"
                                  android:textSize="12sp" />
      
      
                          </LinearLayout>
      
                      </LinearLayout>
      
                      <LinearLayout
                          android:id="@+id/ll_singup_password"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:orientation="vertical">
      
                          <LinearLayout
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_gravity="center"
                              android:background="@mipmap/ic_launcher"
                              android:gravity="left|center_vertical"
      
                              android:orientation="vertical">
      
                              <EditText
                                  android:id="@+id/et_password_login"
                                  android:layout_width="match_parent"
                                  android:layout_height="wrap_content"
                                  android:background="@null"
                                  android:hint="Password"
                                  android:inputType="textPassword"
      
                                  android:maxLength="15"
                                  android:maxLines="1"
      
      
                                  android:paddingLeft="10dp"
                                  android:paddingRight="10dp"
                                  android:singleLine="true"
                                  android:textColor="#777e86"
                                  android:textColorHint="#777e86"
                                  android:textSize="12sp" />
      
      
                          </LinearLayout>
      
      
                          <TextView
                              android:id="@+id/txt_forget_password"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_marginLeft="4dp"
                              android:layout_marginTop="5dp"
                              android:text="Forgot Password?"
                              android:textColor="#ffffff"
                              android:textSize="12sp" />
      
                          <TextView
                              android:id="@+id/txt_sign_up"
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:layout_marginLeft="4dp"
                              android:layout_marginTop="30dp"
                              android:gravity="center"
                              android:text="Forget Password"
                              android:textColor="#ffffff"
                              android:textSize="12sp" />
      
                      </LinearLayout>
      
      
                      <RelativeLayout
      
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_gravity="center"
                          android:layout_marginTop="15dp"
                          android:gravity="center"
                          android:orientation="vertical">
      
                          <ImageView
                              android:id="@+id/login_btn"
                              style="?android:borderlessButtonStyle"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:src="@mipmap/ic_launcher" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_centerHorizontal="true"
                              android:layout_centerVertical="true"
                              android:text="Let me in"
                              android:textColor="#fff"
                              android:textSize="18sp" />
                      </RelativeLayout>
      
      
      
                  </LinearLayout>
      
      
              </LinearLayout>
      
      
          </LinearLayout>
      </ScrollView>
      
      
      <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_marginTop="30dp"
          android:orientation="horizontal"
          android:weightSum="3">
      
      
          <LinearLayout
              android:id="@+id/ll_fb"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:background="@mipmap/ic_launcher"
              android:orientation="horizontal">
      
      
          </LinearLayout>
          </LinearLayout>
      </RelativeLayout>
      

      【讨论】:

      • 您使用它,它在我的设备中运行良好。您将总代码复制到 xml 中并检查它是否正常工作。只有 Uoy 需要更改 mipmap 文件。 @samo
      • 但这不是办法..你为什么要固定高度?这可能因设备而异
      • 虽然它可能仍然有效。在您的回答中解释您所做的更改以及这些更改如何影响输出总是很高兴。
      • @kgandroid 如果你不想要,那么你可以使用 wrap 或 match.here 由于测试目的,我固定了大小。
      猜你喜欢
      • 2011-11-22
      • 1970-01-01
      • 2022-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-28
      • 1970-01-01
      相关资源
      最近更新 更多