解决ScrollView中有listView,造成不屏幕不停留在顶端的问题

这个问题造成的原因 其实是加载ListView之后  ScrollView 的焦点异常   然后看上去被顶上去的


其实有两个方法可以解决 这个问题 

一个是

scrollView.smoothScrollTo(0,20);

顾名思义  这个是让屏幕滚动到顶端的意思。  可有的时候 必须用TabHost  等页面切换Fragment的时候 

这个方法找不到合适的地方加    写在生命周期里  也可能不调用  所有就有了第二种方法

在XML文件里   让listView失去焦点   

只需要在父容器中加入这两条属性
android:focusable="true"
android:focusableInTouchMode="true"


借鉴EditText的方法就可以解决了

以下是完整的XML代码 供大家参考 

<? xml version = "1.0" encoding = "utf-8" ?>
< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
   
android:layout_width = "match_parent"
   
android:layout_height = "match_parent"
   
android:background = "@color/white"
   
android:clickable = "true"
   
android:orientation = "vertical" >

   
< ScrollView
       
android:id = "@+id/scrollView"
       
android:layout_width = "match_parent"
       
android:layout_height = "match_parent"
       
android:scrollbars = "none" >

       
< LinearLayout
           
android:layout_width = "match_parent"
           
android:layout_height = "wrap_content"
           
android:focusable = "true"
           
android:focusableInTouchMode = "true"
           
android:orientation = "vertical" >

           
< cn.dt.app.view.SlideShowView
               
android:id = "@+id/slideshowView"
               
android:layout_width = "match_parent"
               
android:layout_height = "150dp"
               
android:layout_centerHorizontal = "true" />

           
< RelativeLayout
               
android:layout_width = "match_parent"
               
android:layout_height = "wrap_content"
               
android:gravity = "center"
               
android:padding = "12dp" >

               
< ImageButton
                   
android:id = "@+id/link_coupon"
                   
android:layout_width = "46dp"
                   
android:layout_height = "58dp"
                   
android:layout_centerInParent = "true"
                   
android:layout_marginLeft = "@dimen/main_link_margin"
                   
android:layout_marginRight = "@dimen/main_link_margin"
                   
android:background = "@drawable/link_coupon" />

               
< ImageButton
                   
android:id = "@+id/link_notake"
                   
android:layout_width = "46dp"
                   
android:layout_height = "58dp"
                   
android:layout_toLeftOf = "@id/link_coupon"
                   
android:background = "@drawable/link_notake" />

               
< ImageButton
                   
android:id = "@+id/link_machine"
                   
android:layout_width = "46dp"
                   
android:layout_height = "58dp"
                   
android:layout_centerInParent = "true"
                   
android:layout_toRightOf = "@id/link_coupon"
                   
android:background = "@drawable/link_machine" />
           
</ RelativeLayout >

           
< ListView
               
android:id = "@+id/tab_listview"
               
android:layout_width = "match_parent"
               
android:layout_height = "wrap_content"
               
android:divider = "@null"
               
android:dividerHeight = "0dp"
               
android:listSelector = "@color/transparent"
               
android:scrollbars = "none" >
           
</ ListView >
       
</ LinearLayout >
   
</ ScrollView >

   
< Button
       
android:id = "@+id/city_default"
       
android:layout_width = "70dp"
       
android:layout_height = "35dp"
       
android:layout_marginLeft = "3dp"
       
android:layout_marginTop = "10dp"
       
android:background = "@drawable/city_uncheck"
       
android:drawableLeft = "@drawable/icon_location"
       
android:drawablePadding = "7dp"
       
android:gravity = "center_vertical"
       
android:paddingLeft = "8dp"
       
android:text = "北京"
       
android:textColor = "@color/white"
       
android:textSize = "16dp"
       
android:visibility = "gone" />

   
< LinearLayout
       
android:id = "@+id/city_layout"
       
android:layout_width = "wrap_content"
       
android:layout_height = "wrap_content"
       
android:layout_below = "@id/city_default"
       
android:visibility = "gone" >

       
< include layout = "@layout/city_selector" />
   
</ LinearLayout >

   
< include layout = "@layout/nodata_layout" />

</ LinearLayout >

本人才疏学浅,写的不好大家见谅。希望大家多提宝贵意见。以后改进。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值