Android:如果项目超出ViewPager,则ScrollView中的ViewPager不会滚动

时间:2016-12-15 06:41:46

标签: android android-fragments android-viewpager scrollview

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<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:id="@+id/activity_first_time_profile"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:orientation="vertical"
    tools:context="com.vikas.donna.ui.activities.FirstTimeProfileActivity">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="284dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/shape_rectangle_fill_gradient_primary_white">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar_first_time_profile"
                android:layout_width="match_parent"
                android:layout_height="40dp" />


            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/iv_profile_image"
                android:layout_width="130dp"
                android:layout_height="130dp"
                android:layout_below="@id/toolbar_first_time_profile"
                android:layout_centerHorizontal="true"
                android:src="@drawable/userpic" />

            <com.vikas.donna.customcomponents.customfonts.CustomTextView
                android:id="@+id/tv_profile_name"
                style="@style/font_work_sans_medium"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/iv_profile_image"
                android:layout_centerHorizontal="true"
                android:text="Vikas Rohilla"
                android:textColor="@android:color/white"
                android:textSize="22sp" />

            <com.vikas.donna.customcomponents.customfonts.CustomTextView
                android:id="@+id/tv_tag_line"
                style="@style/font_work_sans_medium"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/tv_profile_name"
                android:layout_centerHorizontal="true"
                android:alpha="0.80"
                android:text="I am software engineer"
                android:textColor="@android:color/white"
                android:textSize="11sp" />


            <com.vikas.donna.customcomponents.customfonts.CustomTextView
                android:id="@+id/customTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/tv_tag_line"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="12dp"
                android:background="@drawable/shape_rectangle_fill_primary_trans"
                android:drawableLeft="@drawable/red_dot"
                android:drawablePadding="9dp"
                android:paddingBottom="5dp"
                android:paddingLeft="24dp"
                android:paddingRight="24dp"
                android:paddingTop="5dp"
                android:text="Busy in meeting till 5.00 pm"
                android:textColor="@android:color/white"
                android:textSize="12sp" />

        </RelativeLayout>
    </FrameLayout>

    <android.support.design.widget.TabLayout
        android:id="@+id/tablayout_profile"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        app:tabIndicatorColor="@android:color/transparent"
        app:tabPaddingEnd="0dp"
        app:tabPaddingStart="0dp">

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


    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager_profile"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


</LinearLayout>

如果视图寻呼机中的片段包含长列表,则它不会滚动。即使在添加Scrollview之后,它也会显示静止屏幕。 如果在ViewPager子片段而不是活动中添加Scrollview,则它仅滚动不在部分上方的片段部分。 我现在该怎么办

2 个答案:

答案 0 :(得分:0)

func drawPath()
{
    let origin = "\(currentLocation.latitude),\(currentLocation.longitude)"
    let destination = "\(destinationLoc.latitude),\(destinationLoc.longitude)"


    let url = "https://maps.googleapis.com/maps/api/directions/json?origin=\(origin)&destination=\(destination)&mode=driving&key=YOURKEY"

    Alamofire.request(url).responseJSON { response in
      print(response.request)  // original URL request
      print(response.response) // HTTP URL response
      print(response.data)     // server data
      print(response.result)   // result of response serialization

      let json = JSON(data: response.data!)
      let routes = json["routes"].arrayValue

      for route in routes
      {
        let routeOverviewPolyline = route["overview_polyline"].dictionary
        let points = routeOverviewPolyline?["points"]?.stringValue
        let path = GMSPath.init(fromEncodedPath: points!)
        let polyline = GMSPolyline.init(path: path)
        polyline.map = self.mapView
      }
    }
  }

答案 1 :(得分:0)

从我能够看到的情况来看,你已经将一个水平ViewPager置于垂直ScrollView内,这本身就是一个有问题的安排:是一个手势是为了滚动{{ 1}}或ViewPagerScrollView ListView中的ViewPager进一步加剧了问题:当用户触摸列表时,焦点应放在FragmentListView上?

您可以尝试以下方法之一:

1。尝试使用ScrollViewRecyclerView代替NestedScrollViewListView

2。或者,定义一个ScrollView,在触摸时将焦点锁定在interface上(反之亦然):

ListView

然后创建自定义public interface FocusLock { void lock(); void unlock(); } 并覆盖其ListView方法,如下所示:

dispatchTouchEvent()

public class NestedListView extends ListView{ private FocusLock mCallbackControl; public void setCallback(FocusLock callbackControl) { this.mCallbackControl = callbackControl; } .... @Override public boolean dispatchTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: mCallbackControl.lock(); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mCallbackControl.unlock(); break; } return super.dispatchTouchEvent(event); } } 中,您必须按如下方式初始化Fragment

ListView

希望这是有道理的。

试试这个。其中一种方法应该有效。