冰室辰也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

    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能