`

android中关于scrollview内部组件android:layout_height="fill_parent"无效的解决办法

 
阅读更多

 

今天在调整布局时遇到一个奇怪的问题,在scrollview下加入的组件无论如何也不能自动扩展到屏幕高度,最后对布局文件进行简化,最终得到最简layout配置内容如下:

<!-- 背景:蓝色 -->  
<ScrollView android:layout_width="fill_parent"  android:id="@+id/scrollView1"  
      xmlns:android="http://schemas.android.com/apk/res/android"  
      android:layout_height="fill_parent" android:background="@color/solid_blue">  
  
    <!-- 背景:黄色 -->  
    <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent"   
       android:layout_height="fill_parent" android:background="@color/solid_yellow">  
  
        <TextView android:text="TextView" android:id="@+id/textView1"    
           android:layout_width="wrap_content" android:layout_height="fill_parent"    
           android:layout_weight="1">  
        </TextView>  
  
    </LinearLayout>  
</ScrollView>

 

 

 

 

虽然我的所有组件都设置了android:layout_height="fill_parent",但是结果依然不能扩展到全屏高度,为了看到组件实际大小,我设置了布局组件的背景色,显示效果如下:

 

 

 很明显,scrollview(蓝色)已经扩展到最大高度了,但是其内部的linearlayout(黄色)却没有扩展.

 试了很多办法,就是没有办法让linearlaout组件扩大.

 最终,在一个国外的网站上,找到了答案,描述如下:

  

  ......

   Found the solution myself in the end. The problem was not with the LinearLayout,  but with the ScrollView (seems weird, considering the fact that the ScrollView was expanding, while the LinearLayout wasn't).

The solution was to use android:fillViewport="true" on the ScrollView.

 

 

原文链接:

http://stackoverflow.com/questions/2599837/linearlayout-not-expanding-inside-a-scrollview

 

 

 

果然,需要设置scrollview的fillViewport属性为"true"才能使其子组件可以扩展!

效果:

 

 

向大虾们学习了!

  • 大小: 14.7 KB
  • 大小: 13.3 KB
分享到:
评论

相关推荐

    android顶部滑动导航

    android:layout_height="match_parent" android:background="#F0EFF5" &gt; android:id="@+id/sayit_rl_tab" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_...

    DragLinearLayout-使子View可拖动的LinearLayout.zip

     android:layout_height="match_parent" &gt;      android:layout_width="match_parent"  android:layout_height="wrap_content"  android:text="@string/text" /&gt;      android:layout_width=...

    wkp111_StickLayout-粘性控件,其任意一个子控件都可滑动停留,本质为NestedScrollView和LinearLayout的结合。.zip

     android:layout_height="match_parent"  android:orientation="vertical"&gt;    android:clickable="true"  android:onClick="addView"  android:gravity="center"  android:padding="5dp"  android:text=...

    Android ScrollView无法填充满屏幕的解决办法

    Android ScrollView无法填充满屏幕的解决办法 ScrollView滚动视图是指当拥有很多内容、屏幕显示不完时、需要通过滚动跳来显示的视图、Scrollview的一般用法如下 以下代码在Scrollview里面放了一个RelativeLayout、...

    Android ScrollView使用代码示例

    ScrollView可实现控件在超出屏幕范围的情况下滚动显示。 用法:在XML文件中将需滚动的控件包含在ScrollView中,当控件超出屏幕... android:layout_width=”fill_parent”  android:layout_height=”310dp”  &gt;  

    PullToRefresharp:一个用 C# 编写的用于 Android 的下拉刷新库

    拉动刷新 在C#为 Android 拉动刷新 快速轻松地向您的 Android 应用程序添加下拉刷新功能。 PullToRefresharp 是唯一一个为 Android 上的 ListView、GridView 和 ScrollView 提供下拉... android:layout_height="fill_p

    android listview 水平滚动和垂直滚动的小例子

    网上有很多解决 android listview 水平和垂直滚动的代码,我没有按照他们说的做(以前没搜到 O(∩_∩)O~) 我采用的是添加HorizontalScrollViewJava代码 代码如下: &lt; ScrollView android:id=”@+id/ScrollView01″ ...

    android输入框与文本框加滚动条scrollview示例

    我们都知道EditText与TextView是Android的文本输入框和文本显示框,但是基于手机屏幕的大小因素,如果在需要输入较...TextView android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:

    详解Android ScrollView嵌套EditText出现的滑动问题

    今天项目中需求是写出一个很简单的edittext输入框,但要求当输入字数过长时需要上下滑动以便查看所有文字,因为页面底部有一个”确定”的button,但刚开始输入框内的问题怎么都滑动不了,我一开始就想到了这是事件传递...

    listView和scrollView焦点冲突问题

    在一些项目中需要用到listview嵌套在scrollview中的情况,但会碰到焦点冲突,scrollview焦点覆盖listview造成listview不能滑动,这种情况时要在scrollview中添加android:fillViewport="true"这句,并在listview中...

    TaoBaoDetailView:淘宝宝贝(商品)详情页View(--继续拖动,查看图文详情--)

    TaoBaoDetailView淘宝宝贝(商品)详情页View(--继续拖动,查看图文详情--)程序截图:使用说明:1:需要指定TBLayout的orientation为vertical,并且在TBLayout中添加两个childView,id分别为......_parent"android...

    Android控件之ScrollView用法实例分析

    本文实例讲述了Android控件之ScrollView用法。分享给大家供大家参考。具体如下: ScrollView滚动视图是指当拥有很多内容,屏幕显示不完时,需要通过滚动跳来... android:layout_width=fill_parent android:layout_he

    Android实现日历控件示例代码

    做的是一个酒店的项目,可以选择入住和离开的日期。声明为了省事在网上找的资料,自己修改的逻辑,希望对需要的朋友有帮助。喜欢的给个好评。谢谢啦!祝生活愉快!... android:layout_height=match_parent

    Android开发:TextView加入滚动条示例

    利用scrollview来实现,效果会好很多 代码如下: &lt;ScrollView android:id=”@+id/scrollView1″ android:layout_width=”match_parent” android:layout_height=”150dp” android:fadingEdge=”vertical” android:...

    Android中使用ScrollView实现滑动到底部显示加载更多

    这是效果 主要是onTouchListener监听事件,监视什么时候滑到底部 同时要理解getMeasuredHeight和getHeight的区别 getMeasuredHeight:全部的长度 包括... android:layout_height=fill_parent&gt; &lt;ScrollView andro

    Android scrollview实现底部继续拖动查看图文详情

    本文实例为大家分享了Android实现底部拖动查看图文详情的具体代码,... android:layout_height=fill_parent android:layout_above=@+id/rejcdosjflk android:background=#ffffff android:scrollbars=none&gt; &lt;Lin

    Android实现图片自动切换功能(实例代码详解)

    在Android中图片的自动切换不仅可以实现自动切换,而且还可以使用手动切换。而且一般在切换的时候,在图片下方还带有其他内容的切换,用来标记是第几个... android:layout_height=match_parent android:layout_width=m

    Paralloid:这是chrisjenx弃用的Parraloid库的副本

    适用于Android的Paralloid库 这是弃用的: 特征 当父级滚动时,视差另一个视图。 视差多个背景。 变形金刚,视差以不同的方式和方向 支持: ListView ScrollView Horizo​​... android:layout_height="19

    Android ScrollView只能添加一个子控件问题解决方法

    本文实例讲述了Android ScrollView只能添加一个子控件问题解决方法。分享给大家供大家参考,具体如下: 有下面一段代码 &lt;?xml version=1.0 encoding=utf-8?&gt; &lt;LinearLayout xmlns:android=...

    ScrollDownLayout-一个整体滑动控件.zip

     android:layout_height="match_parent"&gt;  ...你的布局 一些参数的设置:mScrollDownLayout = (ScrollDownLayout) findViewById(R.id.scroll_down_layout); mScrollDownLayout.setMinOffset(0); ...

Global site tag (gtag.js) - Google Analytics