滚动视图内的Android相对布局不在横向模式下滚动

时间:2015-12-29 00:24:45

标签: android scrollview android-relativelayout

您好我已将所有UI元素放在相对布局中,然后将相对布局放在scrollview中以实现屏幕滚动。但布局不是在横向模式下滚动。我在这里错过了什么。任何想法?

谢谢, P

更新:视图也不会在potrait模式下滚动。我添加了一些额外的UI元素,视图也不在此模式下滚动。我正在使用Nexus 6P手机进行测试。

这是xml

<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"
    tools:context="layout.LoginFragment"
    android:fillViewport="true"
  >


 <RelativeLayout
     android:layout_width="match_parent"
     android:layout_height="match_parent">
    <ImageView
        android:layout_width="92dp"
        android:layout_height="92dp"
        android:id="@+id/imageView"
        android:layout_marginLeft="37dp"
        android:layout_marginStart="37dp"
        android:src="@mipmap/ic_logo"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="41dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/login_hello"
        android:id="@+id/login_tv1"

        android:fontFamily="Roboto"
        android:textColor="#000000"
        android:textStyle="bold"
        android:textSize="20dp"

        android:layout_alignTop="@+id/imageView"
        android:layout_toRightOf="@+id/imageView"
        android:layout_toEndOf="@+id/imageView"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="25dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="@string/login_text"
        android:id="@+id/login_tv2"
        android:fontFamily="Roboto"
        android:textColor="#000000"
        android:textSize="16dp"
        android:layout_marginTop="25dp"
        android:layout_alignBottom="@+id/imageView"
        android:layout_alignLeft="@+id/login_tv1"
        android:layout_alignTop="@+id/login_tv1" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:ems="10"
        android:id="@+id/username_et"
        android:fontFamily="Roboto"
        android:layout_centerVertical="true"
        android:hint="@string/login_username"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:textColor="#000000"
        android:layout_alignLeft="@+id/imageView"
        android:layout_alignStart="@+id/imageView"
        android:textColorHint="#000000"
        android:textSize="18dp" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:width="50dp"
        android:ems="10"
        android:id="@+id/password_et"
        android:layout_below="@+id/username_et"
        android:layout_alignLeft="@+id/username_et"
        android:layout_alignStart="@+id/username_et"
        android:layout_marginTop="33dp"
        android:layout_alignRight="@+id/username_et"
        android:layout_alignEnd="@+id/username_et"
        android:password="true"
        android:hint="@string/login_password"
        android:fontFamily="Roboto"
        android:textColorHint="#000000"
        android:textSize="18dp" />

    <Switch
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/rememberme_switch"
        android:layout_below="@+id/password_et"
        android:layout_alignLeft="@+id/password_et"
        android:layout_alignStart="@+id/password_et"
        android:layout_marginTop="53dp"
        android:layout_alignRight="@+id/password_et"
        android:layout_alignEnd="@+id/password_et"
        android:hint="@string/remember_me"
        android:textOff="@string/off"
        android:textOn="@string/on"
        android:textSize="18dp"
        android:clickable="true"
        android:checked="false"
        android:showText="true"
        android:enabled="true"
        android:focusable="true"
        android:trackTint="#000000"
        android:textColorLink="#000000"
        android:textColorHint="#000000" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/help"
        android:id="@+id/help_button"
        android:background="@android:color/transparent"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_below="@+id/rememberme_switch"
        android:layout_alignStart="@+id/rememberme_switch"
        android:layout_marginTop="34dp"
        android:textSize="18dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/login"
        android:id="@+id/login_button"
        android:layout_marginEnd="32dp"
        android:background="@android:color/transparent"
        style="?android:attr/borderlessButtonStyle"
        android:layout_alignTop="@+id/help_button"
        android:layout_alignEnd="@+id/rememberme_switch"
        android:textSize="18dp" />

     <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/error_tv"
         android:textColor="#f92626"
         android:fontFamily="Roboto"
         android:textSize="16dp"
         android:layout_below="@+id/password_et"
         android:layout_alignStart="@+id/password_et"
         android:layout_alignEnd="@+id/login_button" />

 </RelativeLayout>
</ScrollView>`

1 个答案:

答案 0 :(得分:0)

我刚测试了一个类似的布局,它滚动得很好。 scrollview中的内容需要大于滚动条显示的屏幕大小。或者您可以设置滚动视图的大小,只要内部的内容更大,它就会滚动。

<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"
    tools:context="layout.LoginFragment"
    android:fillViewport="true"
  >
 <RelativeLayout
     android:layout_width="match_parent"
     android:layout_height="match_parent">
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Add a lot of text here so the text will fill page and scroll aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
            android:textSize="20dp" />

 </RelativeLayout>
相关问题