6.QMUI----QMUIGroupListView的用法 (条目布局)

1. 引入库

1.最新的库会上传到 JCenter 仓库上,请确保配置了 JCenter 仓库源,然后直接引用:

compile 'com.qmuiteam:qmui:1.0.6'
至此,QMUI 已被引入项目中。

2.需要引用QMUI的样式

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

<style name="AppTheme" parent="QMUI.Compat.NoActionBar">
    
    <item name="colorPrimary">@color/colorPrimaryitem>
    <item name="colorPrimaryDark">@color/colorPrimaryDarkitem>
    <item name="colorAccent">@color/colorAccentitem>
style>

2. QMUIGroupListView的用法

1.布局:
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="?attr/qmui_topbar_height"
    android:background="@color/qmui_config_color_background">

    <com.qmuiteam.qmui.widget.grouplist.QMUIGroupListView
        android:id="@+id/groupListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

ScrollView>
2.用法:

 
QMUIGroupListView mGroupListView=findViewById(R.id.groupListView);
QMUICommonListItemView normalItem = mGroupListView.createItemView("Item 1");
normalItem.setOrientation(QMUICommonListItemView.VERTICAL); //默认文字在左边

QMUICommonListItemView itemWithDetail = mGroupListView.createItemView("Item 2");
itemWithDetail.setDetailText("在右方的详细信息");//默认文字在左边   描述文字在右边

QMUICommonListItemView itemWithDetailBelow = mGroupListView.createItemView("Item 3");
itemWithDetailBelow.setOrientation(QMUICommonListItemView.VERTICAL);
itemWithDetailBelow.setDetailText("在标题下方的详细信息");//默认文字在左边   描述文字在标题下边

QMUICommonListItemView itemWithChevron = mGroupListView.createItemView("Item 4");
itemWithChevron.setAccessoryType(QMUICommonListItemView.ACCESSORY_TYPE_CHEVRON);//默认文字在左边   右侧更多按钮


QMUICommonListItemView itemWithSwitch = mGroupListView.createItemView("Item 5");
itemWithSwitch.setAccessoryType(QMUICommonListItemView.ACCESSORY_TYPE_SWITCH);
itemWithSwitch.getSwitch().setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        Toast.makeText(getActivity(), "checked = " + isChecked, Toast.LENGTH_SHORT).show();
    }
});//默认文字在左边   右侧选择按钮
QMUICommonListItemView itemWithCustom = mGroupListView.createItemView("Item 6");
itemWithCustom.setAccessoryType(QMUICommonListItemView.ACCESSORY_TYPE_CUSTOM);
QMUILoadingView loadingView = new QMUILoadingView(getActivity());
itemWithCustom.addAccessoryCustomView(loadingView);
View.OnClickListener onClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if (v instanceof QMUICommonListItemView) {
            CharSequence text = ((QMUICommonListItemView) v).getText();
            Toast.makeText(getActivity(), text + " is Clicked", Toast.LENGTH_SHORT).show();
        }
    }
};//默认文字在左边   自定义加载框按钮

QMUIGroupListView.newSection(getContext())
        .setTitle("Section 1: 默认提供的样式")
        .setDescription("Section 1 的描述")
        .addItemView(normalItem, onClickListener)
        .addItemView(itemWithDetail, onClickListener)
        .addItemView(itemWithDetailBelow, onClickListener)
        .addItemView(itemWithChevron, onClickListener)
        .addItemView(itemWithSwitch, onClickListener)
        .addTo(mGroupListView);

QMUIGroupListView.newSection(getContext())
        .setTitle("Section 2: 自定义右侧 View")
        .addItemView(itemWithCustom, onClickListener)
        .addTo(mGroupListView);

你可能感兴趣的:(QMUI)