android - Using Scrollable Textview in Fragments doesn't reappear when screen is touched -
i have image , textview in fragment(split screen). have image in top half of screen , textview in bottom half of screen. need textview scrollable. have tried putting scrollable view around textview, showed full screen , no scrollbar. after reading scrollable textviews, discovered there attribute it, used "android:scrollbars="vertical". however, when touch screen scrollbar doesn't appear though there more text display. have implemented ontouchlistener make sure screen being touch active, doesn't cause scrollbar appear. have read post several times: making textview scrollable on android don't see i'm missing. causes scrollbar display? display when screen first appears , fades away. missing make scrollbar reappear when touch textview in fragment?
here xml file:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:orientation="vertical" > <imageview android:id="@+id/bio_imageview" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/black" android:layout_weight="1" android:src="@drawable/bio_pic"/> <textview android:id="@+id/bio_textview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:textsize="18sp" android:textcolor="#000000" android:scrollbars="vertical" android:text="@string/bio_html"/> </linearlayout>
here code:
@override public view oncreateview(layoutinflater inflater, viewgroup parent, bundle savedinstancestate) { if (verbose) log.v(tag, "+++ oncreateview +++"); view v = inflater.inflate(r.layout.fragment_bio, parent, false); // displays title on action bar getactivity().settitle(r.string.bio_title); final textview mtextview = (textview)mview.findviewbyid(r.id.bio_textview); v.setontouchlistener(new ontouchlistener() { @override public boolean ontouch(view v, motionevent e) { //mtextview.settext(html.fromhtml(getstring(r.string.bio_html))); toast.maketext(getactivity(), "screen touched", toast.length_short).show(); return true; } }); mtextview.settext(html.fromhtml(getstring(r.string.bio_html))); setretaininstance(true); return v; }
i found solution own question. not sure if best solution, works well. used 3 linearlayouts: 1 main, 1 image , 1 textview. surrounded linearlayout surrounding textview scrollview. hope helps someone. seems simple, getting right combination of layout_heights, weights , widths tricky newbie myself.
here layout:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" > <imageview android:id="@+id/bio_imageview" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/black" android:src="@drawable/bio_pic"/> </linearlayout> <scrollview android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginleft="10dp" android:layout_marginright="10dp" > <textview android:id="@+id/bio_textview" android:layout_width="match_parent" android:layout_height="wrap_content" android:textsize="18sp" android:textcolor="#000000" android:scrollbars="vertical" android:text="@string/bio_html"/> </linearlayout> </scrollview> </linearlayout>