Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android Material ListView分隔符大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试按照谷歌的指导方针构建一个表视图.

这是我的要求:

>允许组头
>允许组之间的全宽分隔符
>允许项目之间的部分分隔

这是一个显示标题和项目之间的分隔符的图像.
不幸的是,不可能在组之间查看全宽分隔符,但这就像普通的分隔符一样.

Android Material ListView分隔符

我可以构建一个自定义适配器,它接收Item的子类,如HeaderItem和ContactItem.

header.xml就是这样

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:minHeight="48dp"
    android:padding="16dp"
    android:text="Today"
    android:textColor="#8A000000"
    android:textSize="14sp" />

至于contact.xml:

<RelativeLayout xmlns:android="http://@R_262_10906@mas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/friend_profile_picture"
            android:layout_width="40dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_margin="16dp"
            android:scaleType="fitStart"
            android:src="@drawable/ic_home" />

            <TextView
                android:id="@+id/friend_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignWithParentIfMissing="true"
                android:layout_toRightOf="@+id/friend_profile_picture"
                android:paddingTop="16dp"
                android:text="random_text"
                android:textAppearance="@style/TextAppearance.AppCompat.body2" />

            <TextView
                android:id="@+id/friend_state"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layouT_Below="@+id/friend_name"
                android:layout_toRightOf="@+id/friend_profile_picture"
                android:paddingBottom="16dp"
                android:text="random_text"
                android:textAppearance="@style/TextAppearance.AppCompat.body1"
                android:textSize="14sp" />

</RelativeLayout>

现在,我的问题是项目分隔符.全宽分隔符将是普通的listview分隔符.我只是不确定如何做一个部分dividir并让它与普通分频器一起工作.任何提示

如果它更容易/更好,也可以使用RecyclerView和ItemDecorators完成.

解决方法

对于分频器,您可以查看官方的Android设置应用,了解其工作原理.这是“仪表板瓷砖”的 source code

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android open source Project
     Licensed under the Apache License,Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
          http://www.apache.org/licenses/LICENSE-2.0
     Unless required by applicable law or agreed to in wriTing,software
     diStributed under the License is diStributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<LinearLayout
        xmlns:android="http://@R_262_10906@mas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:minHeight="@dimen/dashboard_tile_minimum_height">
    <ImageView
            android:id="@+id/icon"
            android:layout_width="@dimen/dashboard_tile_image_size"
            android:layout_height="@dimen/dashboard_tile_image_size"
            android:scaleType="centerInside"
            android:layout_marginStart="@dimen/dashboard_tile_image_margin_start"
            android:layout_marginEnd="@dimen/dashboard_tile_image_margin_end" />
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:orientation="vertical"
            android:gravity="center_vertical"
            android:layout_weight="1">
            <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">
                <TextView android:id="@+id/title"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:singleLine="true"
                          android:textAppearance="@style/TextAppearance.Tiletitle"
                          android:ellipsize="marquee"
                          android:fadingEdge="horizontal" />
                <TextView android:id="@+id/status"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layouT_Below="@id/title"
                          android:layout_alignStart="@android:id/title"
                          android:textAppearance="@style/TextAppearance.small"
                          android:textColor="?android:attr/textColorSecondary" />
            </RelativeLayout>
        </LinearLayout>
        <View android:id="@+id/tile_divider"
              android:layout_width="match_parent"
              android:layout_height="1dp"
              android:BACkground="?android:attr/dividerVertical" />
    </LinearLayout>
</LinearLayout>

基本上,它可归结为以下内容

>水平方向的LinearLayout,用于包含图片和文本>垂直方向的LinearLayout,用于保存标签分隔线

大佬总结

以上是大佬教程为你收集整理的Android Material ListView分隔符全部内容,希望文章能够帮你解决Android Material ListView分隔符所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。