ScrollView嵌套Linearlayout显示不全的解决办法

以为ScrollView只能嵌套一个元素,所以把几个控件都包裹在了一个LinearLayout中了。但是发现底部显示不全,滑动不到最底下。
代码:

<ScrollView
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
     <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="@color/colorWhite"
            android:orientation="vertical"
            android:padding="15dp">

            <TextView
                android:id="@+id/tv_detail_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Hibernate注解"
                android:textColor="#262626"/>

            <TextView
                android:id="@+id/tv_detail_description"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:ellipsize="end"
                android:maxLines="5"
                android:text="Hibernate注解详细描述"
                android:textSize="12sp"/>
        </LinearLayout>
 </ScrollView>

原因是什么呢?
其实就是LinearLayout中的

android:layout_marginTop="10dp"

这样,ScrllView在开始显示的时候就会向下移10dp。解决办法有很多种
1、把android:layout_marginTop=”10dp”加给ScrllView
2、给Linearlayout再加上两个属性:

     android:paddingTop="10dp"
     android:paddingBottom="8dp"

其实我们还可以直接把ScrllView作为跟布局的,这样就简单很多。

好啦,就是这样。问题不限于嵌套Linearlayout,其他的道理也是一样的。

有问题欢迎提出。

哦对了,欢迎大家加群一起交流,群主是多年开发经验的大牛:

扣扣群号:454430053

转载于:https://www.cnblogs.com/codenoodles/p/6421182.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值