ScrollView显示不全的问题
2017-04-14 10:12
190 查看
在使用高德地图的 api 做定位获取的时候出现界面显示的问题:
我使用 ScrollView 包裹一个 TextView 的方式来布局界面,代码如下:
很简单的代码,我本意是当定位信息 PositionInfo 获取之后,设置到 TextView 显示出来,但获取到的位置信息一直都显示不出来,把手机熄屏后再开屏,定位信息就出来了,然后我就很懵逼啊
后来通过为 TextView 设置背景色,为 SrollView 设置背景色的方式,终于找到原因了
原因就是这个 TextView 的高度的设置不对,初次加载 TextView 时,只有我设置的那一行字,获得的定位信息 PositionInfo 还没有获取到,而当 PositionInfo 获取完成后,再次设置到 TextView 中,虽然设置进去了,但是由于没有重新绘制 View ,所以,这些信息并没有显示出来
而当熄屏后再开屏,程序的 oncreat 方法被重新调用,scrollview 被再次加载,所以能够正确显示
那么怎么解决呢?改变 TextView 的高度设置,修改后代码如下:
这样的话,为 TextView 设置 PositionInfo 的时候就会再次调用 View 的重绘方法,更新 View 了
我使用 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学习 之 问题&解答 ScrollView中嵌套ListView时显示不全的简便解决方案
- 关于在ScrollView中嵌套ListView,ListView显示不全的问题
- scrollview 与 listView 的显示不全问题
- ScrollView 下嵌套 ListView 或 GridView 冲突显示不全问题
- 【Android基础学习】动态设置 listView的高度,解决scrollView中嵌套listview时显示不全的问题
- 解决ScrollView下嵌套ListView、GridView显示不全的问题
- 解决ScrollView下嵌套ListView、GridView显示不全的问题
- 解决ScrollView内嵌套ListView时显示不全的问题
- 详解嵌套ListView、ScrollView布局显示不全的问题
- 解决ScrollView和GridView嵌套时显示不全的问题
- 解决ScrollView下嵌套GridView显示不全的问题
- 解决ScrollView下嵌套ListView、GridView显示不全的问题(冲突)
- 解决ScrollView下嵌套ListView、GridView显示不全的问题
- ScrollView中listview显示不全的问题
- ScrollView 下 ListView显示不全的问题
- 解决android ScrollView滚动显示不全问题
- 解决ScrollView嵌套ListView或ListView嵌套ListView,listview显示不全的问题
- 解决ScrollView下嵌套ListView、GridView显示不全的问题
- scrollview嵌套listview 数据显示不全 问题处理方式集合
- Android开发 详解嵌套ListView、ScrollView布局显示不全的问题