zoukankan      html  css  js  c++  java
  • android程序中界面太大太长太宽如何滚动?

    使用ScrollView即可。

     ScrollView只能容纳一个直接的子控件。

    在Android中编写布局一般会用到scrollview嵌套LinearLayout,使页面可以自适应其高度。但是有的机型页面可以显示全;有的机型页面显示不全,滚动条怎么也滚动不到底部,如下图所示:


    原xml代码:

    <ScrollView

    android:id="@+id/scrollView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">


    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp"
    android:orientation="vertical" >

    </LinearLayout>
    </ScrollView>

    其原因是加了marginTop之后,scrollView初始显示的位置向下移动了10dp,你如果想要让他正常显示,必须在代码里面设置一下scrollView的初始显示位置就可以了。mScrollView.smoothScrollTo(0,0). 或 android:paddingTop="10dp"

    可修改代码为下面的就可以了。

    正确代码:

    <ScrollView

    android:id="@+id/scrollView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">


    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:paddingTop="10dp"
    android:paddingBottom="8dp"
    android:orientation="vertical" >

    </LinearLayout>
    </ScrollView>

  • 相关阅读:
    Windows下如何检测用户修改了系统时间并且把系统时间改回来
    洛谷 1220 关路灯
    洛谷 2279 [HNOI2003]消防局的设立
    洛谷 1498 南蛮图腾
    bzoj 1036 [ZJOI2008]树的统计Count 树链剖分模板
    codevs 1021 玛丽卡 SPFA
    codevs 1077 多源最短路 flyod
    Vijos P1133 装箱问题 01背包
    codevs 1069 关押罪犯 并查集
    codevs 1073 家族 并查集
  • 原文地址:https://www.cnblogs.com/blosaa/p/6261908.html
Copyright © 2011-2022 走看看