【问题标题】:Android : How to get scrollview full height?Android:如何获得滚动视图全高?
【发布时间】:2014-08-14 12:42:17
【问题描述】:

如何找到该滚动视图的总 Y 或高度?在那个滚动视图中有一个带有 Long text 的简单 TextView 。

这是我的代码:

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

我尝试了什么:

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

【问题讨论】:

标签: android scrollview


【解决方案1】:

您可以通过测量孩子的身高来获得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(); 

    } 
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-02
    • 2018-12-03
    • 1970-01-01
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多