【问题标题】:Why listview is not Scroll inside Relative Layout为什么listview不在相对布局内滚动
【发布时间】:2016-01-14 07:08:25
【问题描述】:

我正在尝试滚动 id 为 list 的列表。我尝试了几乎所有的解决方案,但注意到对我有用。我尝试将相对布局放在滚动视图中,但它也不适用于我。我也尝试将列表视图放在滚动视图中,但它也不起作用。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/chat_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<RelativeLayout
    android:id="@+id/head"
    android:background="@color/primary_dark"
    android:layout_width="fill_parent"
    android:layout_height="75dp">

    <TextView
        android:padding="15dp"
        android:id="@+id/grp_heading"
        android:textStyle="bold"
        android:textSize="18sp"
        android:textColor="@android:color/white"
        android:maxLines="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

<ListView
    android:layout_below="@+id/head"
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:divider="@color/white"
    android:dividerHeight="@dimen/pad_5dp"
    android:fastScrollEnabled="true"
    android:paddingBottom="@dimen/pad_10dp"
    android:paddingTop="@dimen/pad_10dp"
    tools:listitem="@layout/chat_item_rcv" >
</ListView>
</RelativeLayout>
<com.github.ksoichiro.android.observablescrollview.ObservableListView
    android:id="@+id/list_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginBottom="32dp"
    android:layout_marginRight="32dp"
    android:src="@drawable/ic_add_white_24dp"
    app:borderWidth="0dp"
    app:fabSize="normal"
    app:rippleColor="@color/primary"
    />

     <com.example.covite.chat_layout.BottomSheetLayout
    android:id="@+id/bottom_sheet"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    app:ft_container_gravity="center"
    app:ft_color="@color/primary">

    <ListView
        android:id="@+id/list_menu"
        android:background="@color/primary"
        android:divider="@null"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</com.valuevision.covite.chat_layout.BottomSheetLayout>
<LinearLayout
    android:id="@+id/send_message_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom"
    android:background="#ffdddddd"
    android:gravity="center_vertical"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/iv_image"
        android:layout_width="40dp"
        android:layout_height="40dp"
        />

    <EditText
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <Button
        android:id="@+id/sendMessageButton"
        android:layout_width="48dp"
        android:layout_height="48dp"
        />

</LinearLayout>

【问题讨论】:

  • 你设置RelativeLayout而不是FrameLayout
  • 为什么要使用框架布局
  • 感谢@AnjaliTripathi 在我使用RelativeLayout 更改FrameLayout 但它不起作用时的回复。

标签: android listview android-listview scrollview android-framelayout


【解决方案1】:

你应该试试

我假设FrameLayout 造成了这个问题。

  1. 使用 RelativeLayout 而不是 FrameLayout

  2. RelativeLayout之外拨打ListView

希望这会有所帮助。

【讨论】:

  • 感谢@IntelliJ 的回复,我试试这个,但它不起作用
  • @ShubhankGupta 可以设置 ListView android:layout_height="match_parent"
  • @ShubhankGupta Ji,你可以试试LinearLayout
  • 它不适用于线性布局我也改变了 match_parent 的列表视图的高度
  • @ShubhankGupta 你可以使用android:layout_height="fill_parent" of RelativeLayout
【解决方案2】:

将包含您的listview 的布局高度更改为match_parent

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

和你的列表视图高度匹配父级

<ListView
    android:layout_below="@+id/head"
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

还要确保您提供给listview 的列表项的长度足以让您滚动。希望这会有所帮助。

编辑: 我不确定BottomSheetLayout 是什么意思,但也可以尝试将其布局高度设置为 match_parent。

<com.example.covite.chat_layout.BottomSheetLayout
    android:id="@+id/bottom_sheet"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="bottom"
    app:ft_container_gravity="center"
    app:ft_color="@color/primary">

或者,如果可能的话,将您的 listviewBottomSheetLayout 中移出,并将其设为您的 RelativeLayout 的子代。

【讨论】:

  • 感谢您的回复,但我试试这个对我不起作用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多