我的列表视图无法显示最后一个项目。

5
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.androidhive.materialtabs.fragments.OneFragment">

    <ListView
        android:id="@+id/olaylar_liste"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></ListView>
</LinearLayout>

enter image description here

最后一项没有显示。请帮忙。


2
在ListView中加入android:layout_height="match_parent" - curiousMind
1
如果您正在使用android.support.design.widget.CoordinatorLayout,则必须使用recycle view。 - Dhaval Parmar
@DhawalSodhaParmar,将其添加到RecyclerView的父级或在XML中添加app:layout_behavior="@string/appbar_scrolling_view_behavior"以实现滚动行为。 - drozdzynski
请检查此处的示例:https://github.com/chrisbanes/cheesesquare。 - Dhaval Parmar
1
问题可能是您的视图页面与父级不匹配。确保它能够正确地延伸到屏幕上。 - Emre Aktürk
显示剩余6条评论
9个回答

41
将此行添加到您的Viewpager中。
android:layout_marginBottom="?attr/actionBarSize"

因为你在底部没有的大小恰好是你的工具栏所占据的大小,

当你滑动到底部时,工具栏(使用新的Android设计)应该被隐藏。

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="?attr/actionBarSize"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

1
挽救了我的一天。谢谢。 - Zaeem Sattar
运行得非常完美。谢谢。 - Zia
1
app:layout_behavior="@string/appbar_scrolling_view_behavior" 这一行是我需要的,谢谢。 - E.Lahu

2

您的设备比 ListView 的内容小一些。

解决方案1.

给您的 olaylar_liste ListView 添加至少 20dppaddingBottom

如果上述方法不起作用,请尝试添加 marginBottom="20dp"

解决方案2.

尝试按照以下方式实现 ScrollView

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.androidhive.materialtabs.fragments.OneFragment">

  <ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="20dp"> //THIS GUY would be useful

    <ListView
        android:id="@+id/olaylar_liste"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </ListView>

  </ScrollView> 

</LinearLayout>

阅读也可以参考:与ScrollView一起使用

希望这能帮助到您。


7
在ScrollView中使用ListView是不好的做法。 - Morozov

0

使用这个

 <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <ListView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                    </ListView>
    </FrameLayout>

0

将此 MainActivity 添加到代码中:

@Override
protected void onResume() {
    super.onResume();
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            );
}

这到底是什么意思? - Zaeem Sattar

0

我正在使用来自de.codecrafters的tableview:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    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.vlad.zimmer.porProgramar$PlaceholderFragment">
    <de.codecrafters.tableview.TableView
        android:id="@+id/tableView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="?attr/actionBarSize"
        />
</RelativeLayout>

添加这行代码,对我来说非常有效:

android:layout_marginBottom="?attr/actionBarSize"


0

试试这个。

<ListView

        android:id="@+id/lv_content"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/bg_listview"
        android:dividerHeight="1dp">

0
在ViewFlipper中添加android:paddingBottom属性,这对我很有效。
<ViewFlipper
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:id="@+id/fragment_workorder_list_viewFlipper"
   android:layout_width="match_parent"
   android:layout_height="fill_parent"
   android:paddingBottom="?attr/actionBarSize">

0
将 android:layout_height="0dp" 添加到我的 ListView,并将 android:layout_height="wrap_content" 添加到我的 ListView 父 ViewGroup,问题得到解决。

-1

你必须在你的列表视图或者RecyclerView中设置android:paddingBottom=""。

    <android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_prod_category"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintRight_toRightOf="parent"
    android:paddingBottom="?attr/actionBarSize"
    app:layout_constraintTop_toTopOf="parent">
</android.support.v7.widget.RecyclerView>

你不能将值""设置为android:paddingBottom! - Jorgesys
@Elenasys 我知道,实际上我想说的是为 paddingBottom 设置一个值,而不是空值。 - Mohammad Davari

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接