【发布时间】:2014-02-17 08:55:07
【问题描述】:
我正在尝试将 ScrollView 放在另一个 ScrollView 中,并尝试了在此站点上找到的答案,但它似乎仍然无法完全正常工作。这是 XML:
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewDirectoryDetailName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/red" />
<LinearLayout
android:id="@+id/linearLayoutDirectoryDetailContainImage"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@drawable/general_image"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:focusableInTouchMode="false" >
<TextView
android:id="@+id/textViewDirectoryDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:autoLink="phone"
android:text="098 123 45 678"
android:textAppearance="?android:attr/textAppearanceLarge" />
</ScrollView>
这里是 Java 代码:
parentScrollView = (ScrollView) findViewById(R.id.scrollView1);
childScrollView = (ScrollView) findViewById(R.id.scrollView2);
parentScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View p_v, MotionEvent p_event) {
childScrollView.getParent().requestDisallowInterceptTouchEvent(
false);
// We will have to follow above for all scrollable contents
return false;
}
});
childScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View p_v, MotionEvent p_event) {
// this will disallow the touch request for parent scroll on
// touch of child view
p_v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
// We will have to follow above for all child scrollable contents
似乎发生了这样的事情:当我在 TextView 中有文本时,它似乎根本不允许我滚动它。它只是滚动父级。但是当我没有文本并且我触摸子 ScrollView 时,它不会滚动父级,所以我猜它正在工作。但是你有什么想法为什么当我有文本时它不起作用?
【问题讨论】:
-
我正在尝试将 ScrollView 放在另一个 ScrollView 中 - 不要这样做,当您有两个不同的滚动区域时,如何期望滚动工作?跨度>
-
这实际上是个坏主意。
-
移除scrollView2。你为什么把它放在首位,你想达到什么目的?
-
我正在为一个客户开发这个应用程序,他已经在 IOS 中实现了这个应用程序。问题是某些项目的描述可能太长,在这种情况下,我使用子滚动视图向下滚动。我见过人们这样做,所以我也想这样做。
-
这可能对你有帮助grishma102.blogspot.in/2014/01/…
标签: android scrollview