0

How do I find total Y or height of that scrollview? In that scrollview there a simple TextView with a Long text .

Here is my code:

<ScrollView
            android:id="@+id/scroll_data"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@color/White" >

            <TextView
                android:id="@+id/text_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:text="@string/scroll_text"
                android:textAlignment="center"
                android:textColor="@color/Black"
                android:textSize="30dp"
                android:textStyle="bold" />
        </ScrollView>

What i tried:

Log.e("ScrollView.FOCUS_DOWN", scrollData.FOCUS_DOWN + ""); ---> Return 120
Log.e("scrollData.getBottom()", scrollData.getBottom() + "");---> Return 0
Log.e("scrollData", scrollData.getMeasuredHeight() + "");---> Return 0
Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78
Dharmik Patel
  • 76
  • 1
  • 11

1 Answers1

2

You can get the height of your ScrollView by measuring its child's height. You can get it done by using ViewTreeObserver

ViewTreeObserver viewTreeObs = view.getViewTreeObserver(); 
viewTreeObs.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
    @Override 
    public void onGlobalLayout() { 
        this.view.getViewTreeObserver().removeGlobalOnLayoutListener(this); 
        int width  = layout.getMeasuredWidth();
        int height = layout.getMeasuredHeight(); 

    } 
});
santoshavss
  • 221
  • 1
  • 6