Android-scrollview里的textview无法撑满屏幕解决方案

来源:互联网 发布:网络订购白兰地 编辑:程序博客网 时间:2024/06/05 16:38

ScrollView里只放一个元素.

当ScrollView里的元素想填满ScrollView时,使用”fill_parent”是不管用的,必需为ScrollView设置:android:fillViewport=”true”。

当ScrollView没有fillVeewport=“true”时, 里面的元素(比如LinearLayout)会按照wrap_content来计算(不论它是否设了”fill_parent”),而如果LinearLayout的元素设置了fill_parent,那么也是不管用的,因为LinearLayout依赖里面的元素,而里面的元素又依赖LinearLayout,这样自相矛盾.所以里面元素设置了fill_parent,也会当做wrap_content来计算.

示例:

<?xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:fillViewport="true">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="vertical">        <TextView            android:layout_width="match_parent"            android:layout_height="match_parent"            android:gravity="center"            android:text="@string/hahhahahaha" />    </LinearLayout></ScrollView>

效果如图:

这里写图片描述

阅读全文
0 0
原创粉丝点击