Android:如何获得scrollview全高?

Android:如何获得scrollview全高?,android,scrollview,Android,Scrollview,如何找到滚动视图的总Y或高度?在这个滚动视图中有一个简单的文本视图和一个长文本 这是我的密码: <ScrollView android:id="@+id/scroll_data" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/White" >

如何找到滚动视图的总Y或高度?在这个滚动视图中有一个简单的文本视图和一个长文本

这是我的密码:

<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>

您可以通过测量子视图的高度来获取您的
滚动视图的高度。您可以使用
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(); 

    } 
});
使用getMeasuredHeightAndState()函数获取高度。检查:或
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(); 

    } 
});