【问题标题】:RelativeLayout is not Scrollable in ScrollViewRelativeLayout 在 ScrollView 中不可滚动
【发布时间】:2014-07-25 15:33:12
【问题描述】:

知道为什么以下布局不可滚动吗?我在ScrollView 中有一个RelativeLayout。视图适合屏幕。但是,只要键盘弹出,它们就会被覆盖。我想在键盘弹出时使屏幕可滚动,因为它覆盖了登录名和密码编辑框,所以很难看到有人在输入什么

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <com.alarm.alarmmobile.android.view.RobotoLightTextView
            android:id="@+id/passcode_login_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="20dp"
            android:text="@string/passcode_login_body"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <EditText
            android:id="@+id/passcode_login_username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/passcode_login_text"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="20dp"
            android:hint="@string/login_textview_username"
            android:singleLine="true" />

        <EditText
            android:id="@+id/passcode_login_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/passcode_login_username"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:hint="@string/login_textview_password"
            android:inputType="textPassword"
            android:singleLine="true" />

        <com.alarm.alarmmobile.android.view.RobotoLightButton
            android:id="@+id/passcode_login_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@id/passcode_login_password"
            android:layout_marginRight="16dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:text="@string/login_button_login" />

    </RelativeLayout>

</ScrollView>

【问题讨论】:

  • 向我们展示它的外观
  • 尝试将android:orientation="vertical" 放入ScrollView。
  • android:orientation="vertical" 没有修复它。

标签: android android-layout android-scrollview android-scroll android-relativelayout


【解决方案1】:

在此布局的活动或片段类上,您必须调用它:

getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

【讨论】:

  • 这行得通,但有没有其他方法可以达到同样的效果?我需要 android:windowSoftInputMode="adjustPan"
  • getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
【解决方案2】:

将此包含在您的清单中:

<activity android:name="..." // your activity here
    ....
    android:windowSoftInputMode="adjustResize|adjustPan">
/>

注意:不确定添加adjustPan 是否会导致问题再次出现。

【讨论】:

  • 这行得通,但有没有其他方法可以达到同样的效果?我需要 android:windowSoftInputMode="adjustPan"
【解决方案3】:

如果所有内容都可以在屏幕上显示,ScrollView 将无法滚动到任何地方。如果有一个组件不完全可见,那么滚动应该可以看到组件的其余部分。无法看到问题所在,很难找到确切的解决方案。

【讨论】:

  • 你是对的,两个编辑框适合屏幕。每当键盘弹出时,它们就会被覆盖。那是我想滚动内容的时候。我该怎么做?
  • 即使所有内容都适合屏幕,我如何使其可滚动?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-09
相关资源
最近更新 更多