【问题标题】:Android Java - ListView and other elements in layoutAndroid Java - ListView 和布局中的其他元素
【发布时间】:2014-07-19 14:17:09
【问题描述】:

我有以下布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginLeft="@dimen/feed_item_margin"
        android:layout_marginRight="@dimen/feed_item_margin"
        android:layout_marginTop="@dimen/feed_item_margin"
        android:orientation="vertical"
        android:paddingBottom="@dimen/feed_item_padding_top_bottom"
        android:paddingTop="@dimen/feed_item_padding_top_bottom" >

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

            <ImageView
                android:contentDescription="@string/feed_icon_typeofgame_description"
                android:id="@+id/typeOfGame"
                android:layout_width="@dimen/feed_item_profile_pic"
                android:layout_height="@dimen/feed_item_profile_pic"
                android:scaleType="fitCenter" />

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

            <RelativeLayout
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="@dimen/feed_itemview_profile_name"
                    android:textStyle="bold" />

                 <TextView
                    android:id="@+id/type"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="@dimen/feed_itemview_type_text"
                    android:layout_alignParentRight="true"
                    android:textColor="@color/feed_item_text_color" />

             </RelativeLayout>

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

        <TextView
            android:id="@+id/txtStatusMsg"
            android:layout_width="fill_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:textSize="@dimen/feed_itemview_desc" />

        <RelativeLayout
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:orientation="horizontal" >

            <Button
            android:id="@+id/buttonRating"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/feed_item_rating_pad_left"
            android:paddingTop="@dimen/feed_item_rating_pad_top" />


        </RelativeLayout>

         <View
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="@color/feed_divider"
            android:layout_marginLeft="1dp"
            android:layout_marginRight="1dp" />

         <ListView
            android:id="@+id/list_comment"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:divider="@color/feed_divider"
            android:dividerHeight="1px" />

    </LinearLayout>

</LinearLayout>

ListView 不向下滚动,见下图

如何解决这个问题?也许添加 ScrollView ?或者把这个元素的上半部分放在view里面,加上listvew的header?

【问题讨论】:

    标签: java android listview android-listview android-scroll


    【解决方案1】:

    正如vishnus 建议的那样 :: 不推荐在滚动视图中添加列表


    • 因为:: Android 对触发哪个滚动事件(列表视图或滚动视图)感到困惑
    • 概述:: 您可以使用 Just Listview 实现目标

    解决方案::

                  - Try to add a header to a listview
    
                  - Second way to use multiple layouts in listview
    

    示例 1 :: See this project

    示例 2::See this Project


    希望对您有所帮助,如果您需要更多帮助,请回复我

    【讨论】:

      【解决方案2】:

      在滚动视图中添加列表视图或反之亦然是不好的,不应该这样做。 将顶部添加为列表视图的标题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-29
        • 2020-06-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多