问题描述
我试图把另一个滚动型滚动型里面,我试图在这个网站上找到的答案,但它仍然似乎并不完全工作。下面是XML:
I'm trying to put a ScrollView inside another ScrollView and I tried the answers found on this site but it still doesn't seems to work completely. Here is the 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 code:
And here is the Java code:
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的文本似乎并没有让我滚动它。它只是滚动父。但是,当我没有文字和我触摸滚动型不滚动父母孩子,所以我想它的工作呢。但是,你有什么想法,为什么它时,我有文字不起作用?
What seems to happen is this: when I have text in the TextView it doesn't seem to let me scroll it at all. It just scrolls the parent. But when I have no text and I touch the child ScrollView it doesn't scroll the parent so I guess it's working then. But do you have any ideas why it doesn't work when I have text?
推荐答案
,其内部又另一个滚动视图滚动视图是不是一个好的做法。然而,你已经使用了code可能会在某些情况下工作。但是,当你有多个元素它可能会失败。在这种情况下,可能无法识别的手势。
Having a Scroll View inside another another Scroll View is not a good practice. However the code you have used could work in some cases. But it might fail when you are having multiple elements. In that case, it might not be able to identify the gesture.
不过,你可以试试这个答案,如果它可以帮助。它禁用父滚动型的触摸,当孩子触摸识别。也看看这个如果它帮助。
However, you can try this answer, if it helps ScrollView Inside ScrollView. It disables the parent ScrollView's touch, when a touch for the child is identified. Also have a look at this post if it helps.
这篇关于另一个滚动视图里面的Android滚动视图不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!