Android : ScrollView won't scroll up when adding new content

on Monday, October 13, 2014


I'm new to android programming™ and I'm trying to write an app that draws natural deduction trees (http://en.wikipedia.org/wiki/Natural_deduction). This kind of trees should rise from the bottom of the screen while you're adding new formulas and hypothesis, hence creating a "reverse tree" whose root is on the bottom of the screen and whose leaves are on the top. I tried to achieve this by using a ScrollView with Horizontal and Vertical scrolling, containing a Relative Layout which contains the various formulas. The XML code looks like this:



<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:fillViewport="true"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/global"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">

<TextView
android:text="A ∧ B ∧ C"
android:id="@+id/root"
android:textSize="14sp"
android:background="@drawable/overline"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>

</HorizontalScrollView>
</LinearLayout>


Basically what I'd like to do is to dynamically add textviews above the root textview (which is initially located at the bottom of the screen), but I found out that when formulas reach the top of the screen the view won't scroll at all, whereas if I try to put root at the top and build the formulas below it scrolls perfectly! Can anyone tell me why? Is there something wrong in what I'm trying to do or is there another way to do it? Thank you in advance!


2 comments:

mam yaar said...

You found an answer? I have the same problem.

mam yaar said...

You found an answer? I have the same problem.

Post a Comment