【问题标题】:Listview adds padding for each item on last itemListview 为最后一项上的每一项添加填充
【发布时间】:2017-07-10 15:55:27
【问题描述】:

列表视图包含球队,球队包含球员。 我有这个由回收适配器填充的列表视图,但我找不到它从哪里得到底部的最后一个填充? 对于我添加到列表中的每个项目,它都会在底部添加更多填充。

如何删除团队底部的填充?

这是保存团队的 xml 布局。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp">

    <android.support.v7.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp">

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Team # X"
                android:textSize="18dp"
                android:gravity="center"
                android:padding="10dp"
                android:id="@+id/make_team_teamName"
                android:textColor="#000000"/>

            <ListView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/make_team_playerList"
                android:paddingBottom="8dp"
                android:clipToPadding="false"
                android:background="@color/colorPrimaryDark">

            </ListView>

        </LinearLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>

这个 xml 包含玩家

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:id="@+id/make_team_player_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:backgroundTint="@color/colorPrimary"
        app:cardCornerRadius="4dp"
        >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Player name"
            android:id="@+id/make_team_playerName"
            android:textColor="@color/colorAccent"
            android:gravity="center"
            style="@style/txt_normal"/>
    </android.support.v7.widget.CardView>
</LinearLayout>

用户看到的就是这个视图

<LinearLayout 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:orientation="vertical"
    android:weightSum="10">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="horizontal"
            android:layout_weight="2"
            android:gravity="center">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/make_team_add_player"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:src="@drawable/add_player"
                android:layout_marginRight="20dp"
                 />

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/make_team_add_team"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:src="@drawable/add_team"
                android:layout_marginLeft="20dp"
                />


        </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="0dp"
        android:layout_weight="8"
        android:id="@+id/make_teams_teamlistView">

        <com.dtu.appname.Adapter.AutofitRecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/make_teams_teamsRecyclerview"
            android:columnWidth="180dp"
            android:clipToPadding="false">


        </com.dtu.appname_v1.Adapter.AutofitRecyclerView>

    </LinearLayout>

    <Button
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentEnd="false"
        android:layout_alignParentBottom="true"
        android:background="@color/colorPrimary"
        android:text="Save"
        android:textColor="@color/colorAccent"
        android:id="@+id/make_teams_done_b"
        />

</LinearLayout>

【问题讨论】:

标签: java android android-layout listview android-studio


【解决方案1】:

可能是 id 为 @+id/make_team_playerList

的列表视图

【讨论】:

  • 是的,但是那个列表视图有什么问题? :)
【解决方案2】:

android:paddingBottom="8dp" 在包含团队的 XML 中。 尝试删除它,看看效果如何。

【讨论】:

  • 我确实尝试将其删除并将其更改为 0 和 2 等,但没有任何反应。也许它是在创建或移动项目时在回收器中的东西?
  • 这可能是 android:paddingBottom="8dp" 和 android:clipToPadding="false" 的结果,看看这个。 stackoverflow.com/questions/40953049/…
  • 也尝试一下.. 我用 cliptopadding 和 paddingbottom 等所有解决方案都红色了。:( 它没有帮助
猜你喜欢
  • 1970-01-01
  • 2011-07-23
  • 1970-01-01
  • 2019-02-15
  • 1970-01-01
  • 2016-02-25
  • 2017-06-30
  • 1970-01-01
  • 2020-02-28
相关资源
最近更新 更多