冰室辰也hl 2017-02-06 10:27 采纳率: 50%
浏览 1812

ListView和ScrollView的嵌套问题,我想让ListView完全展开

xml布局文件里主要是一个ScrollView、若干个LinearLayout、一个ListView。有内容项项的控件,我都把他们的layout height属性设置成了“wrap content”,就是为了让listView能全展开,结果测试的时候ScrollView能正常滚,ListView就60dp左右的高度,没全展开,就显示1项,而我有7项。下面贴布局文件代码:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_news_detail"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.a98198.cppcc.NewsDetailActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:background="#efefef"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <ImageView
                        android:id="@+id/detail_module_image"
                        android:src="@mipmap/ic_launcher"
                        android:layout_width="64dp"
                        android:layout_height="64dp"
                        android:layout_marginTop="4dp"
                        android:layout_marginBottom="4dp"
                        android:layout_marginLeft="4dp"
                        android:layout_marginRight="4dp" />

                    <TextView
                        android:id="@+id/detail_module_name"
                        android:text="板块名称"
                        android:textSize="24sp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="4dp"
                        android:layout_gravity="center"
                        android:layout_weight="1" />

                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:background="#efefef"
                android:orientation="vertical"
                android:layout_marginTop="10dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/detail_news_title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="4dp"
                    android:layout_marginTop="4dp"
                    android:layout_marginBottom="5dp"
                    android:text="新闻标题"
                    android:textSize="30sp"
                    android:layout_gravity="center"/>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:id="@+id/detail_user_image"
                        android:src="@mipmap/ic_launcher"
                        android:layout_width="38dp"
                        android:layout_height="38dp"
                        android:layout_marginTop="4dp"
                        android:layout_marginBottom="4dp"
                        android:layout_marginLeft="4dp"
                        android:layout_marginRight="4dp" />

                    <TextView
                        android:id="@+id/detail_user_name"
                        android:text="用户名称"
                        android:textSize="16sp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="4dp"
                        android:layout_gravity="center"
                        android:layout_weight="1" />

                </LinearLayout>

                <TextView
                    android:id="@+id/detail_news_content"
                    android:textSize="18sp"
                    android:text="新闻内容在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里新闻内容在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里新闻内容在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里在这里"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="4dp"
                    android:layout_marginRight="4dp"
                    android:layout_marginTop="4dp"
                    android:layout_marginBottom="10dp"/>

            </LinearLayout>

            <ImageView
                android:id="@+id/detail_up_image"
                android:layout_width="64dp"
                android:layout_height="64dp"
                android:layout_marginTop="10dp"
                android:layout_gravity="center"
                android:src="@mipmap/ic_launcher"/>
            <TextView
                android:id="@+id/detail_up"
                android:text="34"
                android:textSize="24sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center" />

            <LinearLayout
                android:background="#efefef"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="18sp"
                    android:layout_marginTop="4dp"
                    android:layout_marginLeft="2dp"
                    android:text="评论"/>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="2dp"
                    android:background="#ffffff"></View>

                <ListView
                    android:id="@+id/detail_comment_listview"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"></ListView>
                <!--<ListView-->
                    <!--android:id="@+id/detail_comment_listview"-->
                    <!--android:layout_width="match_parent"-->
                    <!--android:layout_height="wrap_content"-->
                    <!--android:layout_marginTop="5dp"-->
                    <!--android:layout_marginBottom="10dp"-->
                    <!--android:layout_marginLeft="5dp"-->
                    <!--android:layout_marginRight="5dp"-->
                    <!--android:scrollbars="none"></ListView>-->

            </LinearLayout>

        </LinearLayout>

    </ScrollView>


</LinearLayout>
  • 写回答

2条回答

  • 贪心的阿瑜 2017-02-06 11:05
    关注

    我真的…… 这个问题很早之前就有定论了 你这样搞 根本就不支持 可以做 但是根本不提倡 建议你 使用ListView的 addHeader 和 addFooter 方法 或者直接使用过ListView

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)