android 上划卡住tab_【已解决】Android中TAB页面内容不能上下滚动

【问题】

android中一个app,tab页面显示的内容不能滚动:

只能显示部分内容,下面还有其他内容但是由于无法滚动而显示不了:

0b424c0e2931caff155c3c521c5a6eed.png

希望支持Tab的单页内容超过屏幕长度时,支持上下滚动。

【折腾过程】

1.参考:

android – How do you set tab view to scroll – Stack Overflow

去把Tab中LinearLayout加入到ScrollView中。从:<?xml version="1.0" encoding="utf-8"?>

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:id="@+id/tabHost"

>

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@android:id/tabs" />

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:id="@android:id/tabcontent">

变为:<?xml version="1.0" encoding="utf-8"?>

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:id="@+id/tabHost"

>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@android:id/tabs" />

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:id="@android:id/tabcontent">

结果会出错:03-20 03:37:56.885: E/AndroidRuntime(6560): Caused by: java.lang.RuntimeException: Binary XML file line #8: You must supply a layout_width attribute.

2.所以要给ScrollView去加上width等属性:<?xml version="1.0" encoding="utf-8"?>

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:id="@+id/tabHost"

>

android:layout_width="fill_parent"

android:layout_height="fill_parent">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@android:id/tabs" />

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:id="@android:id/tabcontent">

结果就可以正常显示了:

即,可以达到支持滚动的效果:

1014ca5e3ae8047073ba33fc6b9b3458.png

滚动后:

3f37c03c9b4b5b13aea85d18838d1be7.png

另外在小的手机的屏幕上的效果:

b381db63edcf1071bb786e5c3e13e2c1.png

往下滚动的效果:

ba422d572654f017f9ac411f4ca24195.png

【总结】

想要让页面支持滚动的话,则可以通过给所要显示的内容,套上ScrollView即可。

比如给之前Tab的TabHost内部的LinearLayout,套上ScrollView,变成:<?xml version="1.0" encoding="utf-8"?>

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:id="@+id/tabHost"

>

android:layout_width="fill_parent"

android:layout_height="fill_parent">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@android:id/tabs" />

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:id="@android:id/tabcontent">

即可。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值