在Scrollview中处理支持地图片段

问题描述 投票:0回答:1

我想在视图寻呼机中显示医院详细信息。每个页面都有一个医院分支的详细信息,我有2个分支机构。在视图寻呼页面中,我在其xml中膨胀包含地图片段的片段。

查看寻呼机页面片段xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f1ebe7">

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

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_marginStart="15dp"
        android:layout_marginEnd="15dp"
        tools:context="com.example.mapwithmarker.MapsMarkerActivity"/>

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

        <TextView
            android:id="@+id/textViewHospitalAddress"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:fontFamily="@font/latotr_regular"
            android:layout_marginTop="17.6dp"
            tools:text="@string/hospital_address_detail"
            android:textColor="@color/asm_grey_light"
            android:lineSpacingExtra="6sp"
            android:textSize="14sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="15dp"
                android:src="@mipmap/ic_phone_black_18dp"
                android:layout_gravity="center_vertical"/>

            <TextView
                android:id="@+id/textViewHospitalPhoneNumber"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="15dp"
                android:fontFamily="@font/latotr_regular"
                tools:text="@string/hospital_phone_number"
                android:textColor="@color/asm_grey_light"
                android:textSize="18sp"
                android:lineSpacingExtra="2sp"/>
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:layout_marginTop="16dp"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:background="#e5dfdb" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:gravity="center_horizontal"
            android:orientation="horizontal"
            android:paddingTop="20dp">

            <Button
                android:id="@+id/btnHospitalAskForInformation"
                style="@style/RoundedBorderedCreamButton"
                android:layout_width="100dp"
                android:layout_height="30dp"
                android:text="@string/btn_hospital_information"
                android:textAllCaps="false"
                android:layout_marginEnd="6dp"/>

            <Button
                android:id="@+id/askHospitalForRoute"
                style="@style/RoundedGreyButton"
                android:layout_width="100dp"
                android:layout_height="30dp"
                android:text="@string/btn_hospital_route_information"
                android:textAllCaps="false"
                android:layout_marginStart="6dp"/>
        </LinearLayout>

    </LinearLayout>

</LinearLayout>

在包含视图寻呼机的主片段中,当我触摸谷歌地图时,我无法上下滚动。因此,我在主片段中添加了自定义滚动视图,如下所示:

 <FrameLayout 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"
android:layout_height="match_parent"
android:background="#fff"
tools:context="com.example.Fragments.UserProfileFragment">

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeToRefreshUserProfile"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <com.example.Utilities.CustomScrollView
        android:id="@+id/scrollViewUserProfile"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:descendantFocusability="beforeDescendants"
        android:fillViewport="true">

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

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

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="230dp"
                    android:background="@drawable/background_gorsel">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="end"
                        android:paddingEnd="15dp"
                        android:paddingTop="17dp"
                        android:src="@drawable/vector_smart_object_copy_2" />

                    <ImageView
                        android:id="@+id/imageViewUserProfileDetails"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="start"
                        android:paddingBottom="25dp"
                        android:paddingEnd="25dp"
                        android:paddingStart="15dp"
                        android:paddingTop="24dp"
                        android:src="@drawable/vector_smart_object_11" />

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

                        <FrameLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="20dp">

                            <ImageView
                                android:id="@+id/imageViewUserProfileFragmentUserPhoto"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_gravity="center"
                                android:src="@drawable/ellipse_6" />

                            <TextView
                                android:id="@+id/textViewNameInitials"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_gravity="center"
                                android:layout_margin="1dp"
                                android:textAlignment="center"
                                android:textColor="#dddddd"
                                android:textSize="44.9sp"
                                tools:text="BK" />

                            <ImageView
                                android:id="@+id/imageViewAddProfilePhoto"
                                android:layout_width="20dp"
                                android:layout_height="20dp"
                                android:layout_gravity="end|bottom"
                                android:src="@drawable/art" />
                        </FrameLayout>

                        <TextView
                            android:id="@+id/textViewWelcomeUserName"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="8dp"
                            android:layout_marginTop="11dp"
                            android:fontFamily="@font/latotr_bold"
                            android:includeFontPadding="false"
                            android:textColor="#ffffff"
                            android:textSize="25sp"
                            tools:text="Begüm Kırcaoğlu" />

                        <TextView
                            android:id="@+id/textViewWelcomeUserProtocolNo"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:fontFamily="@font/latotr_regular"
                            android:gravity="end"
                            android:lineSpacingExtra="4sp"
                            android:textColor="#ffffff"
                            android:textSize="14sp"
                            tools:text="Protokol No: 1212412" />

                    </LinearLayout>

                </FrameLayout>


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginEnd="15dp"
                    android:layout_marginStart="15dp"
                    android:layout_marginTop="20dp"
                    android:orientation="vertical">

                    <LinearLayout
                        android:id="@+id/linearLayoutUserProfileDisplayResults"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom"
                        android:layout_marginBottom="10dp">

                        <ImageView
                            android:layout_width="60dp"
                            android:layout_height="60dp"
                            android:scaleType="centerInside"
                            android:src="@drawable/tup_testgoruntuleme" />

                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_gravity="bottom"
                            android:layout_weight="1">

                            <FrameLayout
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content">

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_gravity="bottom"
                                    android:fontFamily="@font/latotr_regular"
                                    android:includeFontPadding="false"
                                    android:lineSpacingExtra="3dp"
                                    android:paddingStart="10dp"
                                    android:text="Test &amp; Görüntüleme\nSonuçları"
                                    android:textAlignment="textStart"
                                    android:textColor="@color/asm_grey_light"
                                    android:textSize="18sp" />


                                <Button
                                    android:id="@+id/btnUserProfileNewTestResults"
                                    style="@style/RoundedNotBorderedRedLabel"
                                    android:layout_width="55dp"
                                    android:layout_height="20dp"
                                    android:layout_gravity="end|bottom"
                                    android:layout_marginBottom="2dp"
                                    android:layout_marginEnd="30dp"
                                    android:clickable="false"
                                    android:visibility="gone" />

                            </FrameLayout>

                        </LinearLayout>


                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="end|center_vertical"
                            android:layout_marginTop="8dp"
                            android:src="@drawable/vector_smart_object_1_copy_12" />

                    </LinearLayout>


                    <View
                        android:layout_width="match_parent"
                        android:layout_height="2dp"
                        android:background="#dddddd" />

                    <LinearLayout
                        android:id="@+id/linearLayoutUserProfileAppointments"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:layout_width="60dp"
                            android:layout_height="60dp"
                            android:scaleType="centerInside"
                            android:src="@drawable/telefon_randevu" />


                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_weight="1">

                            <FrameLayout
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content">

                                <TextView
                                    android:layout_width="195dp"
                                    android:layout_height="wrap_content"
                                    android:layout_gravity="bottom"
                                    android:fontFamily="@font/latotr_regular"
                                    android:includeFontPadding="false"
                                    android:paddingStart="10dp"
                                    android:text="Randevularım\n &amp; Muayenelerim"
                                    android:textAlignment="textStart"
                                    android:textColor="@color/asm_grey_light"
                                    android:textSize="18sp" />


                                <Button
                                    android:id="@+id/btnUserProfileNewAppointments"
                                    style="@style/RoundedNotBorderedRedLabel"
                                    android:layout_width="45dp"
                                    android:layout_height="20dp"
                                    android:layout_gravity="end|bottom"
                                    android:layout_marginBottom="2dp"
                                    android:clickable="false"
                                    android:visibility="gone" />

                            </FrameLayout>

                        </LinearLayout>


                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="end|center_vertical"
                            android:src="@drawable/vector_smart_object_1_copy_12" />
                    </LinearLayout>

                    <Button
                        android:id="@+id/btnMakeNewAppointment"
                        style="@style/RoundedYellowButton"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="30dp"
                        android:layout_marginTop="15dp"
                        android:drawableStart="@drawable/takvim_buton"
                        android:gravity="center"
                        android:paddingLeft="100dp"
                        android:paddingRight="80dp"
                        android:text="Yeni Randevu" />


                    <TextView
                        android:id="@+id/textViewUpcomingAppointments"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="12dp"
                        android:layout_marginTop="25dp"
                        android:drawableLeft="@drawable/yaklasan_randevu"
                        android:drawablePadding="10dp"
                        android:fontFamily="@font/latotr_regular"
                        android:lineSpacingExtra="4sp"
                        android:text="Yaklaşan Randevularınız"
                        android:textColor="@color/asm_grey_light"
                        android:textSize="14sp"
                        android:visibility="gone" />


                </LinearLayout>

                <LinearLayout
                    android:id="@+id/linearLayoutUpcomingAppointments"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="15dp"
                    android:layout_marginStart="15dp"
                    android:orientation="vertical">

                </LinearLayout>

                <android.support.v4.view.ViewPager
                    android:id="@+id/viewPagerVisitedDoctors"
                    android:layout_width="match_parent"
                    android:layout_height="330dp"
                    android:layout_marginEnd="15dp"
                    android:layout_marginStart="15dp" />


            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearlayoutHospitalsHeader"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#f1ebe7"
                android:gravity="center_horizontal"
                android:orientation="horizontal">


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="70dp"
                    android:layout_gravity="center_horizontal"
                    android:drawableEnd="@drawable/vector_smart_object_1_copy_10"
                    android:drawablePadding="10dp"
                    android:drawableStart="@drawable/vector_smart_object_copy_4"
                    android:fontFamily="@font/latotr_bold"
                    android:gravity="center"
                    android:padding="10dp"
                    android:text="@string/hospitals"
                    android:textAlignment="gravity"
                    android:textColor="#a1a1a1"
                    android:textSize="15sp" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#f1ebe7"
                android:orientation="vertical">

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">


                    <android.support.design.widget.TabLayout
                        android:id="@+id/tabLayoutHospitalNames"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginEnd="15dp"
                        android:layout_marginStart="15dp"
                        android:animateLayoutChanges="false"
                        app:tabGravity="center"
                        app:tabIndicatorColor="@color/asm_blue"
                        app:tabIndicatorHeight="5dp"
                        app:tabMode="fixed"
                        app:tabSelectedTextColor="@color/asm_blue"
                        app:tabTextAppearance="@style/AppTheme.TextView.Tab"
                        app:tabTextColor="#000" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom"
                        android:layout_marginEnd="15dp"
                        android:layout_marginStart="15dp"
                        android:animateLayoutChanges="true"
                        android:orientation="horizontal">

                        <View
                            android:layout_width="0dp"
                            android:layout_height="5dp"
                            android:layout_gravity="bottom"
                            android:layout_weight="1"
                            android:background="@drawable/siyah_cizgi" />

                        <LinearLayout
                            android:id="@+id/linearLayoutTabIndicator1"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:orientation="vertical">


                            <ImageView
                                android:id="@+id/imageViewTabIndicator1"
                                android:layout_width="wrap_content"
                                android:layout_height="match_parent"
                                android:layout_gravity="center"
                                android:scaleType="fitXY"
                                android:src="@drawable/rectangle_9_copy_6" />

                            <ImageView
                                android:id="@+id/imageViewTabIndicatorBelow1"
                                android:layout_width="match_parent"
                                android:layout_height="5dp"
                                android:background="@drawable/rectangle_9_copy_7"
                                android:scaleType="fitXY" />

                        </LinearLayout>

                        <LinearLayout
                            android:id="@+id/linearLayoutTabIndicator2"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:orientation="vertical">


                            <ImageView
                                android:id="@+id/imageViewTabIndicator2"
                                android:layout_width="wrap_content"
                                android:layout_height="match_parent"
                                android:layout_gravity="center"
                                android:scaleType="fitXY"
                                android:src="@drawable/rectangle_9_copy_6" />

                            <ImageView
                                android:id="@+id/imageViewTabIndicatorBelow2"
                                android:layout_width="match_parent"
                                android:layout_height="5dp"
                                android:background="@drawable/rectangle_9_copy_7"
                                android:scaleType="fitXY" />

                        </LinearLayout>

                        <View
                            android:layout_width="0dp"
                            android:layout_height="5dp"
                            android:layout_gravity="bottom"
                            android:layout_weight="1"
                            android:background="@drawable/siyah_cizgi" />

                    </LinearLayout>

                </FrameLayout>


                <android.support.v4.view.ViewPager
                    android:id="@+id/viewPagerHospitals"
                    android:layout_width="match_parent"
                    android:layout_height="390dp" />

            </LinearLayout>

        </LinearLayout>
    </com.example.Utilities.CustomScrollView>

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

自定义滚动视图效果很好,我可以在触摸谷歌地图时上下滚动。但是,在同一页面上,我有按钮和其他可点击的区域,当我通过触摸任何按钮开始滚动时,自定义滚动视图禁用向上和向下滚动。

虽然我通过触摸任何按钮或可点击区域开始滚动,但如何滚动我的主片段?

自定义滚动视图:

public boolean onInterceptTouchEvent(MotionEvent ev){

final int action = ev.getAction();
switch (action) {
    case MotionEvent.ACTION_DOWN:
        // Disallow ScrollView to intercept touch events.
        requestDisallowInterceptTouchEvent(true);
        // Disable touch on transparent view
        return false;

    case MotionEvent.ACTION_UP:
        // Allow ScrollView to intercept touch events.
        requestDisallowInterceptTouchEvent(false);
        return true;

    case MotionEvent.ACTION_MOVE:
        requestDisallowInterceptTouchEvent(true);
        return false;

    default:
        return true;
}

}

android scrollview android-scrollview supportmapfragment
1个回答
0
投票

我有类似的问题,这是我的解决方案:

switch (action) {
    case MotionEvent.ACTION_MOVE: 
      pager.requestDisallowInterceptTouchEvent(true);
      break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
      pager.requestDisallowInterceptTouchEvent(false);
      break;
}
© www.soinside.com 2019 - 2024. All rights reserved.