NestedScrollView不滚动

NestedScrollView不滚动

本文介绍了NestedScrollView不滚动,由于Editext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临的问题,当我在NestedScrollView以下结构。

下面是我的xml文件:

 < android.support.v4.widget.NestedScrollView
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:背景=@色/ app_base_color
        应用程序:layout_behavior =@字符串/ appbar_scrolling_view_behavior
        机器人:ID =@ + ID / nested_view_editprofile
        机器人:可聚焦=真

        >


        <的LinearLayout
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            机器人:方向=垂直>


            <的LinearLayout
                机器人:layout_width =match_parent
                机器人:layout_height =WRAP_CONTENT
                机器人:背景=@色/ app_base_color
                机器人:weightSum =3>

                <的LinearLayout
                    机器人:layout_width =match_parent
                    机器人:layout_height =match_parent
                    机器人:layout_weight =1>

                    <的TextView
                        机器人:ID =@ + ID / txtvEditProfileUserName
                        机器人:layout_width =match_parent
                        机器人:layout_height =WRAP_CONTENT
                        机器人:layout_weight =0.7
                        机器人:重力=中心
                        机器人:paddingBottom会=10dp
                        机器人:以下属性来=3DP
                        机器人:paddingTop =10dp
                        机器人:文字颜色=@色/橙色/>

                < / LinearLayout中>

                <的LinearLayout
                    机器人:layout_width =match_parent
                    机器人:layout_height =match_parent
                    机器人:layout_weight =0.85
                    机器人:方向=垂直>

                    <的LinearLayout
                        机器人:layout_width =match_parent
                        机器人:layout_height =WRAP_CONTENT
                        机器人:方向=横向
                        机器人:paddingBottom会=5DP
                        机器人:paddingTop =10dp
                        机器人:weightSum =2>

                        <的TextView
                            机器人:ID =@ + ID / txvEditProfileEntertainer
                            机器人:layout_width =match_parent
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_weight =1.3
                            机器人:重力=右
                            机器人:文本=0
                            机器人:文字颜色=@色/橙色/>

                        <的TextView
                            机器人:layout_width =match_parent
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_weight =0.7
                            机器人:以下属性来=3DP
                            机器人:单线=真
                            机器人:文本=艺人
                            机器人:文字颜色=@色/ cement_grey/>

                    < / LinearLayout中>

                    <的LinearLayout
                        机器人:layout_width =match_parent
                        机器人:layout_height =WRAP_CONTENT
                        机器人:方向=横向
                        机器人:paddingBottom会=10dp
                        机器人:paddingTop =5DP
                        机器人:weightSum =2>

                        <的TextView
                            机器人:ID =@ + ID / txvEditProfileSpectator
                            机器人:layout_width =match_parent
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_weight =1.3
                            机器人:重力=右
                            机器人:文本=0
                            机器人:文字颜色=@色/橙色/>

                        <的TextView
                            机器人:layout_width =match_parent
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_weight =0.7
                            机器人:以下属性来=3DP
                            机器人:单线=真
                            机器人:文本=看客
                            机器人:文字颜色=@色/ cement_grey/>

                    < / LinearLayout中>

                < / LinearLayout中>

                <的LinearLayout
                    机器人:layout_width =match_parent
                    机器人:layout_height =match_parent
                    机器人:layout_weight =1.15
                    机器人:重力=中心
                    机器人:方向=垂直>

                    <的ImageButton
                        机器人:ID =@ + ID / imgbtnEditProfileSpactate
                        机器人:layout_width =WRAP_CONTENT
                        机器人:layout_height =WRAP_CONTENT
                        机器人:背景=@机器人:彩色/透明
                        机器人:paddingBottom会=5DP
                        机器人:paddingTop =10dp
                        机器人:SRC =@可绘制/加/>

                    <的TextView
                        机器人:layout_width =match_parent
                        机器人:layout_height =WRAP_CONTENT
                        机器人:layout_weight =0.7
                        机器人:重力=中心
                        机器人:paddingBottom会=10dp
                        机器人:以下属性来=3DP
                        机器人:文本=SPACTATE
                        机器人:文字颜色=@色/橙色/>

                < / LinearLayout中>

            < / LinearLayout中>

            <的TextView
                机器人:ID =@ + ID / txtvcom机器人:layout_width =match_parent
                机器人:layout_height =WRAP_CONTENT
                机器人:背景=@色/ app_base_color
                机器人:填充=10dp
                机器人:文字颜色=@色/ cement_grey/>

            <的TextView
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =match_parent
                机器人:文本=个人信息
                机器人:文字颜色=@色/橙色
                机器人:背景=@可绘制/ app_base_background/>




           < com.customview.CustomEditext
                机器人:ID =@ + ID / edtxEdtPrflName
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =match_parent
                机器人:提示=名称
                机器人:文字颜色=@色/ cement_grey
                机器人:inputType =textImeMultiLine
                机器人:drawableLeft =@可绘制/名称
                机器人:drawablePadding =10dp
                机器人:背景=@可绘制/ profile_pallets_boxes_background
                机器人:启用=真
               机器人:focusableInTouchMode =真
               />

            < com.customview.CustomEditext
                机器人:ID =@ + ID / edtxEdtPrflUserName
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =match_parent
                机器人:提示=用户名
                机器人:文字颜色=@色/ cement_grey
                机器人:inputType =textImeMultiLine
                机器人:drawableLeft =@可绘制/用户名
                机器人:drawablePadding =10dp
                机器人:背景=@可绘制/ profile_pallets_boxes_background
                机器人:启用=假
                机器人:focusableInTouchMode =真
                />

            < com.customview.CustomEditext
                机器人:ID =@ + ID / edtxEdtPrflBio
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =match_parent
                机器人:提示=生物
                机器人:文字颜色=@色/ cement_grey
                机器人:inputType =textImeMultiLine

                机器人:drawableLeft =@可绘制/生物
                机器人:drawablePadding =10dp
                机器人:背景=@可绘制/ profile_pallets_boxes_background
                机器人:启用=真
                机器人:focusableInTouchMode =真
                />

            < com.customview.CustomEditext
                机器人:ID =@ + ID / edtxEdtPrflDOB
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =match_parent
                机器人:提示=出生日期
                机器人:文字颜色=@色/ cement_grey

                机器人:inputType =日期| textImeMultiLine
                机器人:drawableLeft =@可绘制/ DOB
                机器人:drawablePadding =10dp
                机器人:背景=@可绘制/ profile_pallets_boxes_background
                机器人:focusableInTouchMode =真
                机器人:启用=真

                />

            < com.customview.CustomEditext
                机器人:ID =@ + ID / edtxEdtPrflGender
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =match_parent
                机器人:提示=性别
                机器人:文字颜色=@色/ cement_grey
              机器人:inputType =textImeMultiLine
                机器人:编辑=假
                机器人:drawableLeft =@可绘制/性别
                机器人:drawablePadding =10dp
                机器人:背景=@可绘制/ profile_pallets_boxes_background
                机器人:启用=假
                机器人:focusableInTouchMode =真
                />

            <的TextView
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =match_parent
                机器人:文本=私人信息
                机器人:文字颜色=@色/橙色
                机器人:背景=@可绘制/ app_base_background/>

            < com.customview.CustomEditext
                机器人:ID =@ + ID / edtxEdtPrflEmail
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =match_parent
                机器人:提示=电子邮件
                机器人:文字颜色=@色/ cement_grey

                机器人:inputType =textEmailAddress | textImeMultiLine
                机器人:drawableLeft =@可绘制/邮件
                机器人:drawablePadding =10dp
                机器人:背景=@可绘制/ profile_pallets_boxes_background
                机器人:启用=真
                机器人:focusableInTouchMode =真
                />

            < com.customview.CustomEditext
                机器人:ID =@ + ID / edtxEdtPrflPhone
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =match_parent
                机器人:提示=手机
                机器人:文字颜色=@色/ cement_grey

                机器人:inputType =手机| textImeMultiLine
                机器人:最大长度=10
                机器人:drawableLeft =@可绘制/电话
                机器人:drawablePadding =10dp
                机器人:背景=@可绘制/ profile_pallets_boxes_background
                机器人:启用=假
                机器人:focusableInTouchMode =真
                />

        < / LinearLayout中>

    < /android.support.v4.widget.NestedScrollView>
 

现在由于Editext我无法滚动我NestedScrollView为我用下面的解决方案,它做工精细,但它prevent Softkeyboard打开任何Editext。

 公共类CustomEditext扩展的EditText {



    公共CustomEditext(上下文_Context){

        超(_Context);
    }


    公共CustomEditext(上下文的背景下,ATTRS的AttributeSet){

        超(背景下,ATTRS);
    }


    公共CustomEditext(上下文的背景下,ATTRS的AttributeSet,诠释defStyleAttr){
        超(背景下,ATTRS,defStyleAttr);
    }


    @覆盖
    公共布尔的onTouchEvent(MotionEvent事件){
         super.onTouchEvent(事件);

        返回false;
    }


}
 

解决方案

我也有类似的问题。该设计支持库是一个伟大的lib,但它是一个有点马车的时刻。你可以在这里找到关于NestedScrollView一些问题:<一href="https://$c$c.google.com/p/android/issues/list?can=2&q=nestedscrollview&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&cells=tiles"相对=nofollow> NestedScrollView问题。我们将不得不等待下一个更新,直到我们拥有了一个全库。

在那之前,你可以尝试一些替代库,如: ObservableScrollView

这是pretty的简单易用:

1 - 的依赖添加到您的build.gradle文件:

 库{
    mavenCentral()
}

依赖{
    //其他相关性略
    编译com.github.ksoichiro:Android的observablescrollview:1.5.0
}
 

2 - 在布局中,声明如ObservableScrollView:

 &LT; com.github.ksoichiro.android.observablescrollview.ObservableListView
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID /列表
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent/&GT;
 

3 - 在你的活动,实现ObservableScrollViewCallbacks:

 公共类MainActivity扩展AppCompatActivity
  实现ObservableScrollViewCallbacks {
 

4 - 实现所需的方法和他们一起玩:

  @覆盖
  公共无效onScrollChanged(INT scrollY,布尔firstScroll,
    布尔拖动){
  }

  @覆盖
  公共无效onDownMotionEvent(){
  }

  @覆盖
  公共无效onUpOrCancelMotionEvent(ScrollState scrollState){
  }
 

5 - 例如在显示/隐藏在滚动列表中的动作条:

  @覆盖
  公共无效onUpOrCancelMotionEvent(ScrollState scrollState){
    动作条AB = getSupportActionBar();
    如果(scrollState == ScrollState.UP){
      如果(ab.isShowing()){
        ab.hide();
      }
    }否则,如果(scrollState == ScrollState.DOWN){
      如果(!ab.isShowing()){
        ab.show();
      }
    }
  }
 

希望它帮助。

I am facing issue when i have following Structure in NestedScrollView .

Here is my xml file :

<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/app_base_color"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:id="@+id/nested_view_editprofile"
        android:focusable="true"

        >


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


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/app_base_color"
                android:weightSum="3">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1">

                    <TextView
                        android:id="@+id/txtvEditProfileUserName"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.7"
                        android:gravity="center"
                        android:paddingBottom="10dp"
                        android:paddingLeft="3dp"
                        android:paddingTop="10dp"
                        android:textColor="@color/orange" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="0.85"
                    android:orientation="vertical">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:paddingBottom="5dp"
                        android:paddingTop="10dp"
                        android:weightSum="2">

                        <TextView
                            android:id="@+id/txvEditProfileEntertainer"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_weight="1.3"
                            android:gravity="right"
                            android:text="0"
                            android:textColor="@color/orange" />

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_weight="0.7"
                            android:paddingLeft="3dp"
                            android:singleLine="true"
                            android:text="Entertainers"
                            android:textColor="@color/cement_grey" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:paddingBottom="10dp"
                        android:paddingTop="5dp"
                        android:weightSum="2">

                        <TextView
                            android:id="@+id/txvEditProfileSpectator"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_weight="1.3"
                            android:gravity="right"
                            android:text="0"
                            android:textColor="@color/orange" />

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_weight="0.7"
                            android:paddingLeft="3dp"
                            android:singleLine="true"
                            android:text="Spectators"
                            android:textColor="@color/cement_grey" />

                    </LinearLayout>

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1.15"
                    android:gravity="center"
                    android:orientation="vertical">

                    <ImageButton
                        android:id="@+id/imgbtnEditProfileSpactate"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:background="@android:color/transparent"
                        android:paddingBottom="5dp"
                        android:paddingTop="10dp"
                        android:src="@drawable/plus" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.7"
                        android:gravity="center"
                        android:paddingBottom="10dp"
                        android:paddingLeft="3dp"
                        android:text="SPACTATE"
                        android:textColor="@color/orange" />

                </LinearLayout>

            </LinearLayout>

            <TextView
                android:id="@+id/txtvcom"                    android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/app_base_color"
                android:padding="10dp"
                android:textColor="@color/cement_grey" />

            <TextView
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:text="Personal Information"
                android:textColor="@color/orange"
                android:background="@drawable/app_base_background"/>




           <com.customview.CustomEditext
                android:id="@+id/edtxEdtPrflName"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:hint="Name"
                android:textColor="@color/cement_grey"
                android:inputType="textImeMultiLine"
                android:drawableLeft="@drawable/name"
                android:drawablePadding="10dp"
                android:background="@drawable/profile_pallets_boxes_background"
                android:enabled="true"
               android:focusableInTouchMode="true"
               />

            <com.customview.CustomEditext
                android:id="@+id/edtxEdtPrflUserName"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:hint="Username"
                android:textColor="@color/cement_grey"
                android:inputType="textImeMultiLine"
                android:drawableLeft="@drawable/username"
                android:drawablePadding="10dp"
                android:background="@drawable/profile_pallets_boxes_background"
                android:enabled="false"
                android:focusableInTouchMode="true"
                />

            <com.customview.CustomEditext
                android:id="@+id/edtxEdtPrflBio"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:hint="Bio"
                android:textColor="@color/cement_grey"
                android:inputType="textImeMultiLine"

                android:drawableLeft="@drawable/bio"
                android:drawablePadding="10dp"
                android:background="@drawable/profile_pallets_boxes_background"
                android:enabled="true"
                android:focusableInTouchMode="true"
                />

            <com.customview.CustomEditext
                android:id="@+id/edtxEdtPrflDOB"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:hint="Date of Birth"
                android:textColor="@color/cement_grey"

                android:inputType="date|textImeMultiLine"
                android:drawableLeft="@drawable/dob"
                android:drawablePadding="10dp"
                android:background="@drawable/profile_pallets_boxes_background"
                android:focusableInTouchMode="true"
                android:enabled="true"

                />

            <com.customview.CustomEditext
                android:id="@+id/edtxEdtPrflGender"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:hint="Gender"
                android:textColor="@color/cement_grey"
              android:inputType="textImeMultiLine"
                android:editable="false"
                android:drawableLeft="@drawable/gender"
                android:drawablePadding="10dp"
                android:background="@drawable/profile_pallets_boxes_background"
                android:enabled="false"
                android:focusableInTouchMode="true"
                />

            <TextView
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:text="Private Information"
                android:textColor="@color/orange"
                android:background="@drawable/app_base_background"/>

            <com.customview.CustomEditext
                android:id="@+id/edtxEdtPrflEmail"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:hint="Email"
                android:textColor="@color/cement_grey"

                android:inputType="textEmailAddress|textImeMultiLine"
                android:drawableLeft="@drawable/mail"
                android:drawablePadding="10dp"
                android:background="@drawable/profile_pallets_boxes_background"
                android:enabled="true"
                android:focusableInTouchMode="true"
                />

            <com.customview.CustomEditext
                android:id="@+id/edtxEdtPrflPhone"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:hint="Phone"
                android:textColor="@color/cement_grey"

                android:inputType="phone|textImeMultiLine"
                android:maxLength="10"
                android:drawableLeft="@drawable/phone"
                android:drawablePadding="10dp"
                android:background="@drawable/profile_pallets_boxes_background"
                android:enabled="false"
                android:focusableInTouchMode="true"
                />

        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>

Now due to Editext i am unable to scroll my NestedScrollView for that i use below solution and which work fine but it prevent Softkeyboard Opening for any Editext .

public class CustomEditext extends EditText {



    public CustomEditext(Context _Context){

        super(_Context);
    }


    public CustomEditext(Context context, AttributeSet attrs){

        super(context,attrs);
    }


    public CustomEditext(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) {
         super.onTouchEvent(event);

        return false;
    }


}
解决方案

I had a similar issue. The Design Support Library is a great lib, but it's a bit buggy at the moment. You can find some issues regarding NestedScrollView here: NestedScrollView Issues.We will have to wait for the next updates until we have a fully working lib.

Until then, you can try some alternative libs, such as: ObservableScrollView.

It is pretty simple to use:

1 - Add the dependency to your build.gradle file:

repositories {
    mavenCentral()
}

dependencies {
    // Other dependencies are omitted
    compile 'com.github.ksoichiro:android-observablescrollview:1.5.0'
}

2 - In your Layout, declare the ObservableScrollView like:

<com.github.ksoichiro.android.observablescrollview.ObservableListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

3 - In your Activity, implement ObservableScrollViewCallbacks:

public class MainActivity extends AppCompatActivity
  implements ObservableScrollViewCallbacks {

4 - Implement the required methods and play with them:

@Override
  public void onScrollChanged(int scrollY, boolean firstScroll,
    boolean dragging) {
  }

  @Override
  public void onDownMotionEvent() {
  }

  @Override
  public void onUpOrCancelMotionEvent(ScrollState scrollState) {
  }

5 - Example on showing/hiding the ActionBar on scrolling the list:

@Override
  public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    ActionBar ab = getSupportActionBar();
    if (scrollState == ScrollState.UP) {
      if (ab.isShowing()) {
        ab.hide();
      }
    } else if (scrollState == ScrollState.DOWN) {
      if (!ab.isShowing()) {
        ab.show();
      }
    }
  }

Hope it helps.

这篇关于NestedScrollView不滚动,由于Editext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 14:23