android - 我为android设计的底部 ListView 没有完全显示

标签 android android-layout listview android-studio scrollview

您可以看到下面属于布局设计的代码。

<LinearLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="5dp">

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

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

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

                <ImageView
                        android:id="@+id/profilePic2"
                        android:layout_width="@dimen/feed_item_profile_pic"
                        android:layout_height="@dimen/feed_item_profile_pic"
                        android:scaleType="fitCenter" >
                    </ImageView>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:paddingLeft="@dimen/feed_item_profile_info_padd" >

                    <TextView
                        android:id="@+id/name2"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:textSize="@dimen/feed_item_profile_name"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/timestamp2"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:textColor="@color/timestamp"
                        android:textSize="@dimen/feed_item_timestamp" />

                    <TextView
                        android:text="TextView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/textCategory2"
                        android:layout_weight="1"
                        android:textStyle="normal|bold"/>

                </LinearLayout>

            </LinearLayout>

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


                <TextView
                    android:id="@+id/content2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingBottom="5dp"
                    android:paddingLeft="@dimen/feed_item_status_pad_left_right"
                    android:paddingRight="@dimen/feed_item_status_pad_left_right"
                    android:paddingTop="@dimen/feed_item_status_pad_top"
                    android:layout_weight="1"/>

                <ImageView
                    android:id="@+id/contentImage2"
                    android:layout_width="match_parent"
                    android:background="@color/white"
                    android:scaleType="fitCenter"
                    android:visibility="visible"
                    android:cropToPadding="false"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    app:srcCompat="@drawable/bg_parent_rounded_corner"
                    android:layout_weight="1"/>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:isScrollContainer="false"
                    android:keepScreenOn="false"
                    android:measureWithLargestChild="false"
                    android:verticalScrollbarPosition="defaultPosition"
                    android:paddingBottom="10dp">

                    <TextView
                        android:text="@string/yorumlar"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/textView"
                        android:layout_weight="1"/>

                    <ListView
                        android:layout_width="match_parent"
                        android:id="@+id/comList"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="false"
                        android:clipChildren="false"
                        android:headerDividersEnabled="false"
                        />
                </LinearLayout>

            </LinearLayout>

        </LinearLayout>
    </ScrollView>

</LinearLayout>

我们可以在屏幕顶部看到帖子的详细信息,评论在屏幕底部。尽管 ScrollView 包含 ListView 并且我有“layout_height:wrap_content”,但评论并没有完全显示。出现第一条评论,但其他评论不显示滚动。

感谢您的回答

Screenshot

最佳答案

您必须更改以下内容才能显示列表:

  • 将根线性布局的高度从包装内容更改为匹配父级。
     android:layout_height="match_parent"
    
  • 做同样的事情来 ScrollView
    android:layout_height="match_parent"
    

  • 3 现在改变listview的高度,我给了android:layout_height="500dp"这个。您可以根据自己的要求进行调整。

    注意:如果不提供静态高度, ListView 将无法在 ScrollView 中工作。所以你必须给高度为 400..500dp 或者你可以删除 ScrollView 。

    关于android - 我为android设计的底部 ListView 没有完全显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41924793/

    相关文章:

    android - 向 FloatingActionButton 添加多个行为

    java - 将 Android 应用程序连接到 phpmyadmin - 无法连接错误

    android - Cursor Adapter 的用途是什么?

    android - 最佳实践 : Update ArrayAdapter continuously

    android - PopupWindow 中的 ScrollView 没有滚动效果

    android - 如何在 robotium 中获取当前可见的 android.support.v4.app.Fragment

    android - 为什么 Horizo​​ntalScrollView 不能在 HTCDesire 2.2 中滚动,而只能在模拟器上滚动?

    android - 在抽屉导航中突出显示所选项目

    java - 如何使我的 ListViewItem 看起来像 Twitter 应用程序?

    android - RecyclerView 动态标题