ScrollView显示不全的问题

在使用高德地图的 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 了

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值