Android “滚动”仅适用于两个手指

Android “滚动”仅适用于两个手指,android,scroll,fragment,nestedscrollview,Android,Scroll,Fragment,Nestedscrollview,我正在制作一个有滚动视图的布局,并且它有一个被多次实现的布局。 问题是,当我在我的设备中运行时,只有当我用一个手指握住滚动条并用另一个手指滑动滚动条时,滚动条才会工作 我已经找过这个问题了,但仍然没有答案 以下是xml代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:t

我正在制作一个有滚动视图的布局,并且它有一个被多次实现的布局。 问题是,当我在我的设备中运行时,只有当我用一个手指握住滚动条并用另一个手指滑动滚动条时,滚动条才会工作

我已经找过这个问题了,但仍然没有答案

以下是xml代码:

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
tools:context="com.example.catarinaferreira.tripmanager.frag_results"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:layout_height="500dp"
>

<!-- TODO: Update blank fragment layout -->
<TextView
    android:text="TextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/id_experience"
    android:visibility="gone" />

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/scroll_results"
    android:scrollIndicators="right"
    style="@style/DialogFragmentStyle"
    android:background="@color/light_orange"
    android:scrollbarSize="10dp"
    android:overScrollMode="ifContentScrolls"
    android:nestedScrollingEnabled="true"
    android:focusableInTouchMode="true"
    android:focusable="true">



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/results"
        android:orientation="vertical"
        android:background="@android:color/transparent"
        >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/layout_results"
            android:background="@color/white">

            <Space
                android:layout_width="match_parent"
                android:layout_height="10dp" />

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/results_top_information">

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="wrap_content"
                    android:id="@+id/layout_results_exp_name"
                    android:layout_height="25dp">

                    <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:layout_height="match_parent"
                            app:srcCompat="@drawable/ic_experience"
                            android:id="@+id/imageView14"
                            android:layout_weight="1"
                            android:layout_width="50dp" />

                        <Space
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:layout_width="10dp" />

                        <TextView
                            android:text="Passeio às grutas"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:id="@+id/txt_results_experience"
                            android:textSize="18sp"
                            android:textStyle="normal|bold"
                            android:textColor="@android:color/background_dark"
                            android:fontFamily="casual" />
                    </LinearLayout>

                    <Space
                        android:layout_width="match_parent"
                        android:layout_height="5dp" />

                </LinearLayout>

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="wrap_content"
                    android:id="@+id/layout_results_location"
                    android:layout_height="20dp">

                    <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:layout_height="match_parent"
                            app:srcCompat="@drawable/ic_location"
                            android:id="@+id/imageView15"
                            android:layout_width="50dp" />

                        <Space
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:layout_width="10dp" />

                        <TextView
                            android:text="Marina Albufeira"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:id="@+id/txt_results_location"
                            android:textSize="18sp"
                            android:textColor="@android:color/background_dark"
                            android:fontFamily="sans-serif" />
                    </LinearLayout>

                    <Space
                        android:layout_width="match_parent"
                        android:layout_height="5dp" />

                </LinearLayout>

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    android:id="@+id/layout_results_boat">

                    <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:layout_height="match_parent"
                            app:srcCompat="@drawable/ic_boat"
                            android:id="@+id/imageView16"
                            android:layout_width="50dp" />

                        <Space
                            android:layout_height="match_parent"
                            android:layout_width="10dp" />

                        <TextView
                            android:text="Golfinho"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:id="@+id/txt_results_boat"
                            android:textSize="16sp"
                            android:textColor="@android:color/background_dark"
                            android:fontFamily="casual" />
                    </LinearLayout>
                </LinearLayout>

            </LinearLayout>

            <Space
                android:layout_width="match_parent"
                android:layout_height="10dp" />

            <ImageView
                android:layout_width="match_parent"
                app:srcCompat="@drawable/experience"
                android:id="@+id/img_results_experience"
                android:layout_height="150dp"
                android:scaleType="centerCrop" />

            <Space
                android:layout_width="match_parent"
                android:layout_height="10dp" />

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:id="@+id/results_date_time"
                android:layout_height="15dp">

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/layout_results_date">

                    <ImageView
                        android:layout_height="match_parent"
                        app:srcCompat="@drawable/ic_calendar"
                        android:id="@+id/imageView19"
                        android:layout_weight="1"
                        android:layout_width="20dp" />

                    <Space
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:layout_width="5dp" />

                    <TextView
                        android:text="23/02/2017"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/txt_results_date"
                        android:layout_weight="1"
                        android:textColor="@android:color/black"
                        android:textSize="14sp" />

                    <Space
                        android:layout_width="20dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/layout_results_time">

                    <ImageView
                        android:layout_width="20dp"
                        android:layout_height="match_parent"
                        app:srcCompat="@drawable/ic_time"
                        android:id="@+id/imageView20"
                        android:layout_weight="1" />

                    <Space
                        android:layout_width="5dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1" />

                    <TextView
                        android:text="07:00"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/txt_results_time"
                        android:layout_weight="1"
                        android:textSize="14sp"
                        android:textColor="@android:color/black" />

                    <Space
                        android:layout_width="20dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/layout_results_duration">

                    <ImageView
                        android:layout_width="20dp"
                        android:layout_height="match_parent"
                        app:srcCompat="@drawable/ic_duration"
                        android:id="@+id/imageView21"
                        android:layout_weight="1" />

                    <Space
                        android:layout_width="5dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1" />

                    <TextView
                        android:text="01:00"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/txt_results_duration"
                        android:layout_weight="1"
                        android:textSize="14sp"
                        android:textColor="@android:color/black" />
                </LinearLayout>
            </LinearLayout>

            <Space
                android:layout_width="match_parent"
                android:layout_height="10dp" />

            <LinearLayout
                android:orientation="horizontal"
                android:layout_height="match_parent"
                android:id="@+id/results_prices"
                android:layout_width="match_parent">

                <ImageView
                    app:srcCompat="@drawable/ic_prices"
                    android:id="@+id/imageView22"
                    android:layout_weight="1"
                    android:foregroundGravity="top"
                    android:layout_gravity="top"
                    android:layout_width="50dp"
                    android:layout_height="50dp" />

                <Space
                    android:layout_height="match_parent"
                    android:layout_width="10dp" />

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:id="@+id/layout_results_price_list">

                    <TextView
                        android:text="Preços"
                        android:layout_width="match_parent"
                        android:id="@+id/txt_price_name"
                        android:fontFamily="casual"
                        android:textStyle="normal|bold"
                        android:textSize="18sp"
                        android:textColor="@android:color/black"
                        android:layout_height="25dp" />

                    <Space
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="5dp"
                        android:background="@color/laranja_logo">

                    </LinearLayout>

                    <Space
                        android:layout_width="match_parent"
                        android:layout_height="5dp"
                        android:layout_weight="1" />

                    <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/layout_set_prices"></LinearLayout>

                </LinearLayout>

            </LinearLayout>

            <Space
                android:layout_width="match_parent"
                android:layout_height="10dp" />

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:background="#ffe0be"
                android:id="@+id/results_more_informations"
                android:layout_height="25dp">

                <Space
                    android:layout_width="10dp"
                    android:layout_height="match_parent" />

                <ImageView
                    app:srcCompat="@drawable/ic_plus"
                    android:id="@+id/img_more_informations"
                    android:layout_height="match_parent"
                    android:clickable="true"
                    android:layout_width="30dp" />

                <TextView
                    android:text="Mais informações"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/txt_more_informations"
                    android:layout_weight="1"
                    android:textSize="18sp"
                    android:textStyle="normal|bold"
                    android:textColor="@android:color/background_dark"
                    android:foregroundGravity="center"
                    android:gravity="center" />
            </LinearLayout>

            <Space
                android:layout_width="match_parent"
                android:layout_height="10dp" />

            <TextView
                android:text="25 lugares disponíveis"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/txt_disponibility"
                android:gravity="center"
                android:background="@android:color/holo_green_light"
                android:textColor="@android:color/black" />

            <Space
                android:layout_width="match_parent"
                android:layout_height="10dp" />

            <Button
                android:text="Reservar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/btn_reservation"
                android:background="@color/azul_logo"
                android:textColor="@android:color/background_light"
                android:textStyle="normal|bold"
                android:textSize="24sp"
                android:fontFamily="casual"
                android:gravity="center" />

        </LinearLayout>

    </LinearLayout>
</ScrollView>
</LinearLayout>

以下是片段代码:

   public class frag_results extends Fragment {
public frag_results() {
    // Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    final View myinflatedview = inflater.inflate(R.layout.fragment_frag_results, container, false);





    LinearLayout results_layout = (LinearLayout) myinflatedview.findViewById(R.id.results);
    LinearLayout to_hide = (LinearLayout)myinflatedview.findViewById(R.id.layout_results); //Layout for using multiple times
    to_hide.setVisibility(View.GONE); //We set that gone so we can build all of the other ones in a for cicle

    final View myScroll = (View) myinflatedview.findViewById(R.id.scroll_results);

    ScrollView scroll_view = (ScrollView)myinflatedview.findViewById(R.id.scroll_results);




    for (int n = 0; n < 5; n++) { }//Builds the results

        //SOME CODE FOR BUILDING THE SAME LAYOUT MULTIPLE TIMES
    return myinflatedview;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    //When clicked in "plus" image, it opens the fragment "more informations"
    ImageView img_more_informations = (ImageView) getActivity().findViewById(R.id.img_more_informations);
    img_more_informations.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {  frag_more_informations frag_more_informations = new frag_more_informations();


            FragmentManager manager = getActivity().getSupportFragmentManager();
            manager.beginTransaction().replace(R.id.framelayout_secundary, frag_more_informations, frag_more_informations.getTag()).commit();
        }
    });
}


@Override
//Pressed return button - returns to the home menu
public void onResume() {
    super.onResume();
    getView().setFocusableInTouchMode(true);
    getView().requestFocus();
    getView().setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {

            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK){
                View show_layout_secundary = (View)getActivity().findViewById(R.id.framelayout_secundary);  //LAYOUT - SHOWS SECUNDARY PAGES
                View show_layout_principal = (View)getActivity().findViewById(R.id.framelayout_principal); //LAYOUT - SHOWS INITIAL PAGE
                        show_layout_principal.setVisibility(View.VISIBLE);
                     show_layout_secundary.setVisibility(View.INVISIBLE);
                return true;
            }
            return false;
        }
    });
}
公共类frag_结果扩展片段{
公共框架结果(){
//必需的空公共构造函数
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
//为该碎片膨胀布局
最终视图myinflatedview=充气机。充气(R.layout.fragment\u frag\u结果,容器,错误);
LinearLayout results_layout=(LinearLayout)myinflatedview.findviewbyd(R.id.results);
LinearLayout to_hide=(LinearLayout)myinflatedview.findviewbyd(R.id.layout_results);//用于多次使用的布局
to_hide.setVisibility(View.GONE);//我们设置了它,这样我们就可以在for循环中构建所有其他的
final View myScroll=(View)myinflatedview.findviewbyd(R.id.scroll\u结果);
ScrollView scroll\u view=(ScrollView)myinflatedview.findViewById(R.id.scroll\u结果);
for(int n=0;n<5;n++){}//生成结果
//多次构建同一布局的一些代码
返回我的膨胀视图;
}
@凌驾
ActivityCreated上的公共无效(@Nullable Bundle savedinStateCState){
super.onActivityCreated(savedInstanceState);
//在“plus”图像中单击时,会打开片段“更多信息”
ImageView img\u more\u informations=(ImageView)getActivity().findViewById(R.id.img\u more\u informations);
img_更多信息。setOnClickListener(新视图。OnClickListener(){
@凌驾
public void onClick(视图v){frag_more_informations frag_more_informations=新frag_more_informations();
FragmentManager=getActivity().getSupportFragmentManager();
manager.beginTransaction().replace(R.id.framelayout\u secundary,frag\u more\u informations,frag\u more\u informations.getTag()).commit();
}
});
}
@凌驾
//按下返回按钮-返回主菜单
恢复时公开作废(){
super.onResume();
getView().setFocusableInTouchMode(true);
getView().requestFocus();
getView().setOnKeyListener(新视图.OnKeyListener()){
@凌驾
公共布尔onKey(视图v、int keyCode、KeyEvent事件){
if(event.getAction()==KeyEvent.ACTION\u UP&&keyCode==KeyEvent.keyCode\u BACK){
视图show_layout_secundary=(View)getActivity().findviewbyd(R.id.framelayout_secundary);//布局-显示第二页
视图show_layout_principal=(视图)getActivity().findviewbyd(R.id.framelayout_principal);//布局-显示初始页面
显示\u布局\u主体.setVisibility(View.VISIBLE);
显示\u布局\u secundary.setVisibility(视图.不可见);
返回true;
}
返回false;
}
});
}

它有一个愚蠢的解决方案


我们只需要简单地用嵌套的ScrollView来替换导航抽屉主目录中的父级
CoordinatorLayout
NestedScrollView

如此多的布局嵌套?您知道
findViewById()的成本吗
对于您所做的每一个嵌套?是的,但这还没有完成,是为了用外部数据填充每个布局。有些布局被禁用,因为它们可能需要隐藏。部分原因是,匹配父项和换行内容存在多个问题。如果父项的高度或宽度为
换行内容,则子项必须为请将
match\u parent
分别作为高度或宽度更正所有这些冲突并重试,然后将
fill\u parent
替换为
match\u parent