【问题标题】:ScrollView in Fullscreen全屏滚动视图
【发布时间】:2014-10-25 12:31:52
【问题描述】:

我必须在全屏模式下开发应用程序,现在我有一个公式 带有一些文本编辑和一些按钮。如果键盘弹出它会隐藏 两个按钮,所以我把所有东西都放在一个滚动视图中:

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dip"
    tools:context="controller.RegsiterActivity" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/register_textview_firstname"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dip"
            android:singleLine="true"
            android:text="@string/text_firstname" />

        <EditText
            android:id="@+id/register_textedit_firstname"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dip"
            android:inputType="text" />

        <TextView
            android:id="@+id/register_textview_lastname"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dip"
            android:singleLine="true"
            android:text="@string/text_lastname" />

        <EditText
            android:id="@+id/register_textedit_lastname"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dip"
            android:inputType="text" />

        <TextView
            android:id="@+id/register_textview_email"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dip"
            android:singleLine="true"
            android:text="@string/text_email" />

        <EditText
            android:id="@+id/register_textedit_email"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dip"
            android:inputType="textEmailAddress" />

        <TextView
            android:id="@+id/register_text_password"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dip"
            android:singleLine="true"
            android:text="@string/text_password" />

        <EditText
            android:id="@+id/register_textedit_password"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dip"
            android:inputType="text" />

        <Button
            android:id="@+id/register_button_register"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/button_register" />

        <Button
            android:id="@+id/register_button_cancel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/button_cancel" />

    </LinearLayout>

</ScrollView>

正如我所说,我必须全屏运行我的应用程序:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

但是当我现在运行我的应用程序时,没有出现 scrollView 并且没有滚动工作。

我怎样才能使滚动视图工作?

【问题讨论】:

  • 考虑添加android:fillViewport="true"
  • scrollview 高度设置为match_parent
  • 两者都添加了。没有任何改变。
  • 你能看到屏幕上的所有内容吗
  • 不,我看不到完整的内容。

标签: android android-scrollview


【解决方案1】:

您可能应该添加到ScrollView 的第一个属性是:

android:fillViewport="true" 

当设置为 true 时,如果需要,此属性会使滚动视图的子视图扩展到 ScrollView 的高度。当child高于ScrollView时,该属性无效。

另外,将fill_parent 布局尺寸更改为match_parent,因为fill_parent 已被弃用,您可以摆脱任何烦人的警告。

进一步,将LinearLayoutlayout_height 属性更改为match_parent,使其与屏幕上的ScrollView 配置更改(例如拉起键盘)一起调整大小。

此外,与@karvoynistas 的建议类似,您应该查看windowSoftInputMode 属性。

您可以将此属性添加到您的活动中:

<activity
    android:windowSoftInputMode="stateVisible|adjustResize"
    ...>

    <!-- ... -->

</activity>

这样的效果是(根据Android docs):

为了确保系统将您的布局调整到可用空间——这确保您的所有布局内容都可以访问(即使它可能需要滚动)

adjustPan 值添加到windowSoftInputMode 属性可能会起作用,但不是您想要的,因为它可能会导致一些不寻常的影响(阅读下文)。

两个值的Android Docs比较:

调整大小

Activity 的主窗口总是会调整大小,以便为屏幕上的软键盘腾出空间。

adjustPan

Activity 的主窗口没有调整大小来为软键盘腾出空间。相反,窗口的内容会自动平移,因此当前焦点永远不会被键盘遮挡,用户始终可以看到他们正在输入的内容。这通常不如调整大小可取,因为用户可能需要关闭软键盘才能到达窗口的模糊部分并与之交互。

【讨论】:

    【解决方案2】:

    如果在键盘出现之前定位对您来说没问题,则无需为此放置scrollView。 为了避免使用键盘出现滚动问题,您所要做的就是在清单文件中的特定活动声明中设置以下内容:

    android:windowSoftInputMode="adjustPan"
    

    【讨论】:

      【解决方案3】:

      在应用程序的清单文件中,将以下行添加到&lt;activity/&gt;

      android:windowSoftInputMode="stateAlwaysHidden|adjustResize|adjustPan"
      

      这个link 陈述了同样的问题。

      【讨论】:

      • 您提供的链接与全屏模式下的滚动问题无关。并没有解决问题。
      猜你喜欢
      • 2020-04-27
      • 2014-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-03
      相关资源
      最近更新 更多