zoukankan      html  css  js  c++  java
  • ScrollView内部元素如何做到fill_parent 或者 match_parent?

    转  : http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/0704/1629.html

    ScrollView滚动视图是指当拥有很多内容,屏幕显示不完时,需要通过滚动跳来显示的视图。Scrollview的一般用法如下

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"                                                                                                                                                                                                                                                                                                                                                                                                   
        android:background="@color/white"
    >
    <LinearLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
        >
            <TextView
                android:id="@+id/first_edittext"
                android:layout_width="fill_parent"
                android:background="@color/gray"
                android:layout_height="fill_parent"
                android:text="文字"
            />
        </LinearLayout>   
    </ScrollView>

    得到下面的界面:

    其中白色部分是scrollView,灰色部分是TextView,很明显,scrollview(白色)已经扩展到最大高度了,但是其内部的TextView(灰色)却没有扩展.可明明TextView的layout_height="fill_parent",为什么没占满呢?是因为TextView的上层LinearLayout为wrap_content的原因吗?

    但是换成fill_parent还是一样的(实际上Scrollview的第一层View的layout_weight在sdk中是建议为wrap_content的)。

     

    后来在stackoverflow上找到了原因: http://stackoverflow.com/questions/2599837/linearlayout-not-expanding-inside-a-scrollview

    要让ScrollView内部元素的 fill_parent 起作用必须设置android:fillViewport="true"

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
    >
  • 相关阅读:
    [转载-声网]18个实时音视频开发中会用到开源项目
    linux shell命令之wc/split及特殊字符
    RTP推流及验证
    Ubuntu18.04提示wifi无法连接
    ubuntu上Android开发环境及依赖项
    HLS playlist典型示例
    ffmpeg-hls实现分析
    AOSP中的HLS协议解析
    使用ffmpeg搭建HLS直播系统
    流媒体之HLS——综述(二)
  • 原文地址:https://www.cnblogs.com/woaixingxing/p/5825875.html
Copyright © 2011-2022 走看看