【问题标题】:Android scroll issueAndroid滚动问题
【发布时间】:2017-12-27 06:05:38
【问题描述】:

我设计了一个顶部带有徽标图像视图和标题的屏幕,高度约为 80 dp。然后一个框架布局垂直保持在它旁边。框架布局动态加载片段。该片段包含一个带有输入字段的滚动视图。问题来了,当焦点转到编辑文本时,整个屏幕向上滚动。我只希望片段中的滚动视图滚动。顶部区域必须固定。请仔细阅读为 Holder Activity 及其片段提供的布局设计。 我只希望滚动视图缩小到键盘上方。任何人都可以帮助我,因为我是 android 开发的新手。

HolderActivity 布局

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

<ImageView
    android:id="@+id/patternImageView"
    style="@style/WFImageViewPatternBG"/>

<ImageView
    android:id="@+id/titleImageView"
    style="@style/WFImageViewTitle"
    android:layout_centerHorizontal="true"/>

<TextView
    android:id="@+id/fertilityTextView"
    style="@style/WFTextStyleFertilityTitle"
    android:layout_below="@id/titleImageView"
    />

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragmentPlaceholder"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/fertilityTextView"
    android:layout_marginTop="20dp">

    <!-- Fragment will go here eventually, but it's not added in the layout -->

</FrameLayout>

片段活动布局

<RelativeLayout 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="com.ideasurge.winfertility.CreateAccountInputFragment">

<ScrollView
    android:id="@+id/inputScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/createAcctNextBtn">

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

        <TextView
            android:id="@+id/createAcctTitleTextView"
            style="@style/WFTextStyleBoldPinkTitle"
            android:text="Create An Account" />

        <EditText
            android:id="@+id/first_name_edit_txt"
            style="@style/WFEditTextStyle"
            android:hint="First Name"
            android:background="@drawable/rounded_border_pink"
            android:layout_marginTop="20dp"
            android:layout_below="@+id/createAcctTitleTextView" />

        <EditText
            android:id="@+id/last_name_edit_txt"
            style="@style/WFEditTextStyle"
            android:hint="Last Name"
            android:background="@drawable/rounded_border_pink"
            android:layout_below="@+id/first_name_edit_txt" />

        <EditText
            android:id="@+id/email_pwd_edit_txt"
            style="@style/WFEditTextStyle"
            android:hint="Email Address"
            android:background="@drawable/rounded_border_pink"
            android:layout_below="@+id/last_name_edit_txt" />

        <EditText
            android:id="@+id/phone_no_edit_txt"
            style="@style/WFEditTextStyle"
            android:hint="Phone Number"
            android:background="@drawable/rounded_border_pink"
            android:layout_below="@+id/email_pwd_edit_txt" />

        <EditText
            android:id="@+id/create_pwd_edit_txt"
            style="@style/WFEditTextStyle"
            android:hint="Create Password"
            android:background="@drawable/rounded_border_pink"
            android:layout_below="@+id/phone_no_edit_txt" />

        <EditText
            android:id="@+id/dob_edit_txt"
            style="@style/WFEditTextStyle"
            android:hint="Date of Birth"
            android:background="@drawable/rounded_border_pink"
            android:layout_below="@+id/create_pwd_edit_txt" />

        <EditText
            android:id="@+id/gender_edit_txt"
            style="@style/WFEditTextStyle"
            android:hint="Gender"
            android:background="@drawable/rounded_border_pink"
            android:layout_below="@+id/dob_edit_txt" />

        <TextView
            android:id="@+id/companySectionTitle"
            style="@style/WFTextStyleSectionPinkTitle"
            android:text="Your company may provide Fertility Benefits."
            android:layout_marginLeft="40dp"
            android:layout_marginRight="40dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="20dp"
            android:layout_below="@+id/gender_edit_txt"/>

        <EditText
            android:id="@+id/company_edit_txt"
            style="@style/WFEditTextStyle"
            android:hint="Name of Company"
            android:background="@drawable/rounded_border_pink"
            android:layout_below="@+id/companySectionTitle" />

        <EditText
            android:id="@+id/insurance_id_edit_txt"
            style="@style/WFEditTextStyle"
            android:hint="Insurance Subscriber ID"
            android:background="@drawable/rounded_border_pink"
            android:layout_below="@+id/company_edit_txt" />

    </RelativeLayout>

</ScrollView>

<Button
    android:id="@+id/createAcctNextBtn"
    style="@style/WFButtonStylePink"
    android:text="NEXT"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="20dp"
    android:layout_alignParentBottom="true"
    />

【问题讨论】:

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


    【解决方案1】:

    这可能会有所帮助:

    android:windowSoftInputMode="adjustPan"
    

    像这样在清单活动标签中使用它:

    <activity  
        android:name=".Activity"
        android:windowSoftInputMode="adjustPan" />
    

    在这里你可以使用其他选项来代替adjustpan

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-03
      • 2015-10-23
      • 2012-08-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多