Reputation: 9023
I am developing 1 application in that i need 1 scrollview
inside this scrollview i need to put scrolling textview
/webview(that must display some static string) but must scrollable inside scrollview but not working
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/img_view_flag"
android:layout_marginTop="17dp"
android:paddingBottom="20dip">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/rel_layout"
android:layout_marginTop="15dp"
android:maxLines="2"
android:scrollbars="vertical"
android:text="Medium Text"
android:paddingBottom="10dip"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
In myjava file i have done...
scrollView1 = (ScrollView) findViewById(R.id.scrollView1);
// scrollView2 = (ScrollView) findViewById(R.id.scrollView2);
tv = (TextView) findViewById(R.id.tv_desc);
tv.setText("this is 1\n"+"this is 2"+"\n this ix 3\n"+"this is 4\n\n"+"this is 5\n" );
scrollView1.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub Log.v("PARENT",
// "PARENT TOUCH");
Log.v("PARENT", "PARENT TOUCH");
findViewById(R.id.tv_desc).getParent()
.requestDisallowInterceptTouchEvent(false);
return false;
}
});
tv.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
Log.v("TextView", "CHILD TOUCH");
arg0.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
But not working for me.... what wrong or what i am missing?
Upvotes: 1
Views: 2828
Reputation: 1
Found a solution.
Add following lines towards end of your OnCreate() function
scrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
textView.getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
textView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
textView.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
Upvotes: -1
Reputation: 12733
You have to use below line in your code to make textview scrollable..
yourTextView.setMovementMethod(new ScrollingMovementMethod())
Upvotes: 5