ScrollView显示不全的问题

    xiaoxiao2021-04-16  40

    在使用高德地图的 api 做定位获取的时候出现界面显示的问题:

    我使用 ScrollView 包裹一个 TextView 的方式来布局界面,代码如下:

    <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/bt_location"> <TextView android:id="@+id/tv_show" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/bt_location"/> </ScrollView>

    很简单的代码,我本意是当定位信息 PositionInfo 获取之后,设置到 TextView 显示出来,但获取到的位置信息一直都显示不出来,把手机熄屏后再开屏,定位信息就出来了,然后我就很懵逼啊

    后来通过为 TextView 设置背景色,为 SrollView 设置背景色的方式,终于找到原因了

    原因就是这个 TextView 的高度的设置不对,初次加载 TextView 时,只有我设置的那一行字,获得的定位信息 PositionInfo 还没有获取到,而当 PositionInfo 获取完成后,再次设置到 TextView 中,虽然设置进去了,但是由于没有重新绘制 View ,所以,这些信息并没有显示出来

    而当熄屏后再开屏,程序的 oncreat 方法被重新调用,scrollview 被再次加载,所以能够正确显示

    那么怎么解决呢?改变 TextView 的高度设置,修改后代码如下:

    <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/blue" android:layout_below="@id/bt_location"> <TextView android:id="@+id/tv_show" android:layout_width="match_parent" android:layout_height="wrap_content" //高度参数改为wrap_content android:background="@color/colorPrimaryDark" android:layout_below="@id/bt_location"/> </ScrollView>

    这样的话,为 TextView 设置 PositionInfo 的时候就会再次调用 View 的重绘方法,更新 View 了

    转载请注明原文地址: https://ju.6miu.com/read-672851.html

    最新回复(0)