2015-10-08 244 views
0

我有以下佈局設計。這裏ViewPager包含幾個EditText的片段。CollapsingToolbarLayout,Android ViewPager和EditText - >平滑滾動(垂直滾動)問題

我的問題是因爲EditText(android:enabled =「false」)垂直滾動無法正常工作(平滑)。如果我刪除EditText並用TextView替換而不是正常滾動。

我的觀察是EditText消耗焦點事件,因此垂直滾動不起作用。如果我觸摸某個區域的edittext沒有超過滾動將是光滑的。

如何使用CollapsingToolbarLayout在ViewPager中的片段中使用EditText平滑滾動。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ProgressBar 
     android:id="@+id/mProgressBar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:progressTint="@color/colorPrimary" 
     android:visibility="gone" /> 

    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/root_coordinator" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true"> 

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/app_bar_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:fitsSystemWindows="true" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

      <android.support.design.widget.CollapsingToolbarLayout 
       android:id="@+id/collapsing_toolbar_layout" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fitsSystemWindows="true" 
       app:contentScrim="?attr/colorPrimary" 
       app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

       <ProgressBar 
        android:id="@+id/mProgressBarForImageView" 
        android:layout_width="wrap_content" 
        android:layout_height="250dp" 
        android:layout_gravity="center" 
        android:progressDrawable="@color/backgroundColor_white" 
        android:progressTint="@color/backgroundColor_white" 
        style="@android:style/Widget.Holo.Light.ProgressBar" 
        android:visibility="gone" /> 

       <ImageView 
        android:id="@+id/profilePicImageView" 
        android:layout_width="match_parent" 
        android:layout_height="250dp" 
        android:scaleType="centerCrop" 
        android:src="@drawable/default_profile_pic" 
        app:layout_collapseMode="parallax" /> 

       <android.support.v7.widget.Toolbar 
        android:id="@+id/app_bar" 
        android:layout_width="match_parent" 
        android:layout_height="?attr/actionBarSize" 
        app:layout_collapseMode="pin" 
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

      </android.support.design.widget.CollapsingToolbarLayout> 

      <android.support.design.widget.CollapsingToolbarLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:layout_scrollFlags="scroll|enterAlways"> 

       <android.support.design.widget.TabLayout 
        android:id="@+id/tab_layout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@color/colorAccent" 
        app:layout_collapseMode="pin" 
        app:tabIndicatorColor="@android:color/white" 
        app:tabSelectedTextColor="@android:color/white" 
        app:tabTextColor="#EEE" /> 
      </android.support.design.widget.CollapsingToolbarLayout> 

     </android.support.design.widget.AppBarLayout> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/view_pager" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|right" 
      android:layout_margin="16dp" 
      android:src="@drawable/ic_edit" 
      app:borderWidth="0dp" 
      app:fabSize="normal" /> 
    </android.support.design.widget.CoordinatorLayout> 
</FrameLayout> 

一個使用的片段是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

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

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Phone No." /> 

      <EditText 
       android:id="@+id/phoneNoEditText" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:enabled="false" 
       android:inputType="number" 
       android:singleLine="true" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Father Phone No." /> 

      <EditText 
       android:id="@+id/fatherPhoneNoEditText" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:enabled="false" 
       android:inputType="number" 
       android:singleLine="true" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Mother Phone No." /> 

      <EditText 
       android:id="@+id/motherPhoneNoEditText" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:enabled="false" 
       android:inputType="number" 
       android:singleLine="true" /> 

      <Button 
       android:id="@+id/updateButton" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@color/colorAccent" 
       android:text="Update" 
       android:textColor="@android:color/white" 
       android:visibility="gone" /> 

      <ProgressBar 
       android:id="@+id/mProgressBar" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:visibility="gone" /> 
     </LinearLayout> 
    </android.support.v4.widget.NestedScrollView> 
</LinearLayout> 

回答

-1

在你editText,你可以試試這個:

android:focusable="true" 
android:focusableInTouchMode="true" 
+0

嘗試,但沒有運氣:( – Dishant