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

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

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   android:fitsSystemWindows="true"
    android:orientation="vertical"
    android:fillViewport="true"
    tools:context="com.zhb86.nongxin.cn.ui.activity.usedcar.ATUsedCarDetail">

    <LinearLayout
        android:layout_marginTop="@dimen/dip_10"
        android:id="@+id/rl"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="@dimen/dip_20"
        android:layout_marginRight="@dimen/dip_20"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="公司介绍"
            android:textColor="#333"
            android:textSize="@dimen/dip_15" />

        <TextView
            android:id="@+id/company_introduction"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/dip_10"
            android:minLines="2"
            android:text=""
            android:textColor="#666666"
            android:textSize="@dimen/dip_14" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="公司文化"
            android:textColor="#333"
            android:textSize="@dimen/dip_15" />

        <TextView
            android:id="@+id/company_culture"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/dip_10"
            android:minLines="2"
            android:text=""
            android:textColor="#666666"
            android:textSize="@dimen/dip_14" />

        <View
            android:id="@+id/lineone"
            android:layout_width="match_parent"
            android:layout_height="@dimen/common_line"
            android:layout_marginTop="@dimen/dip_10"
            android:background="@color/common_line" />

        <TextView
            android:id="@+id/use_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/dip_10"
            android:text="公司地址"
            android:textColor="#333"
            android:textSize="@dimen/dip_15" />

        <TextView
            android:id="@+id/com_address"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/list_item_selector"
            android:drawableLeft="@drawable/nongjiaddress1x"
            android:maxLines="1"
            android:paddingTop="@dimen/dip_10"
            android:paddingBottom="@dimen/dip_10"
            android:text=""
            android:textColor="#666666"
            android:textSize="@dimen/dip_14" />


        <View
            android:id="@+id/linethree"
            android:layout_width="match_parent"
            android:layout_height="@dimen/common_line"
            android:background="@color/common_line" />


        <TextView
            android:id="@+id/customer_information"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/dip_10"
            android:text="公司网站"
            android:textColor="#333"
            android:textSize="@dimen/dip_15" />

        <TextView
            android:id="@+id/com_website"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/dip_10"
            android:text=""
            android:textColor="#666666"
            android:textSize="@dimen/dip_14" />
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

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

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

 android:paddingTop="10dp"
 android:paddingBottom="8dp"
posted @   黑帅-quan  阅读(3330)  评论(0编辑  收藏  举报
编辑推荐:
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
阅读排行:
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 【.NET】调用本地 Deepseek 模型
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
点击右上角即可分享
微信分享提示