我想把一个滚动视图在另一个滚动视图,我试着在这个网站上找到的答案,但它似乎仍然不完全工作。下面是XML:Android的滚动视图在另一个滚动视图不滚动
<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它不会滚动父,所以我想它的工作。但是,当我有文字时,你有什么想法可以解决它不起作用的问题吗?
*我试图把一个滚动型另一个滚动型内* - 不这样做,你怎么指望滚动上班的时候你有两个不同的滚动区域? – Luksprog
这实际上是一个坏主意。 –
删除scrollView2。你为什么首先把它放在那里,你想达到什么目的? – 2Dee