您的位置:首页 > 移动开发 > Android开发

ScrollView显示不全的问题

2017-04-14 10:12 190 查看
在使用高德地图的 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 了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  界面 android