Android : Android textview with scrollbars inside a layout with scrollbar

on Monday, October 27, 2014


That's xml file with layout:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center|center_vertical"
android:orientation="vertical"
android:weightSum="1">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/sc"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">

<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
>

<ImageView
android:id="@+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/hello"
/>

<TextView
android:id="@+id/textview3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
>

<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

<TextView
android:id="@+id/openText"
android:visibility="gone"
android:layout_gravity="start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical"
/>

<Button
android:id="@+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>


So, I have a TextView with id "openText", and on click on button it appears (scrollable) with text, height i set programmatically,



TextView openText = (TextView) findViewById(R.id.openText);
openText.setMaxHeight(textHeight);


Everything is fine, but when an image has a big height so a main scrollview appears, it only scrolls, and a textview stops scrolling :(.


0 comments:

Post a Comment