AndroidAndroid 从建项目开始-(完整项目)Android知识

Android从0到完整项目(6)下拉列表与分段选择

2017-07-17  本文已影响184人  移动开发者_李挺哲

简单的下拉列表(仿美团)和 分段选择

分段选择

TabLayout 实现分段选择与底部导航

下拉菜单

美团下拉选择

IOS Segemnt

IOS Segemnt

Segemnt 的简单使用方法

  <com.ningcui.mylibrary.viewLib.segment.SegmentedGroup

                    android:layout_gravity="center"
                    android:id="@+id/segmented4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:orientation="horizontal"
                    segmentedgroup:sc_border_width="1dp"
                    segmentedgroup:sc_corner_radius="5dp"
                    segmentedgroup:sc_tint_color="#F44336">

                    <com.ningcui.mylibrary.viewLib.segment.AwesomeRadioButton
                        android:id="@+id/button41"
                        style="@style/RadioButton"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        arb:awesome_text="{fa_apple}" />

                    <com.ningcui.mylibrary.viewLib.segment.AwesomeRadioButton
                        android:id="@+id/button42"
                        style="@style/RadioButton"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        arb:awesome_text="VS" />

                    <com.ningcui.mylibrary.viewLib.segment.AwesomeRadioButton


                        android:id="@+id/button43"
                        style="@style/RadioButton"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        arb:awesome_text="{fa_google} " />

仿美团使用代码

 private void initView() {
        //init city menu
        final ListView cityView = new ListView(this);
        cityAdapter = new GirdDropDownAdapter(this, Arrays.asList(citys));
        cityView.setDividerHeight(0);
        cityView.setAdapter(cityAdapter);

        //init age menu
        final ListView ageView = new ListView(this);
        ageView.setDividerHeight(0);
        ageAdapter = new ListDropDownAdapter(this, Arrays.asList(ages));
        ageView.setAdapter(ageAdapter);

        //init sex menu
        final ListView sexView = new ListView(this);
        sexView.setDividerHeight(0);
        sexAdapter = new ListDropDownAdapter(this, Arrays.asList(sexs));
        sexView.setAdapter(sexAdapter);

        //init constellation
        final View constellationView = getLayoutInflater().inflate(R.layout.custom_layout, null);
        GridView constellation = ButterKnife.findById(constellationView, R.id.constellation);
        constellationAdapter = new ConstellationAdapter(this, Arrays.asList(constellations));
        constellation.setAdapter(constellationAdapter);
        TextView ok = ButterKnife.findById(constellationView, R.id.ok);
        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDropDownMenu.setTabText(constellationPosition == 0 ? headers[3] : constellations[constellationPosition]);
                mDropDownMenu.closeMenu();
            }
        });

        //init popupViews
        popupViews.add(cityView);
        popupViews.add(ageView);
        popupViews.add(sexView);
        popupViews.add(constellationView);

        //add item click event
        cityView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                cityAdapter.setCheckItem(position);
                mDropDownMenu.setTabText(position == 0 ? headers[0] : citys[position]);
                mDropDownMenu.closeMenu();
            }
        });

        ageView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ageAdapter.setCheckItem(position);
                mDropDownMenu.setTabText(position == 0 ? headers[1] : ages[position]);
                mDropDownMenu.closeMenu();
            }
        });

        sexView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                sexAdapter.setCheckItem(position);
                mDropDownMenu.setTabText(position == 0 ? headers[2] : sexs[position]);
                mDropDownMenu.closeMenu();
            }
        });

        constellation.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                constellationAdapter.setCheckItem(position);
                constellationPosition = position;
            }
        });

        //init context view
        TextView contentView = new TextView(this);
        contentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        contentView.setText("内容显示区域");
        contentView.setGravity(Gravity.CENTER);
        contentView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);

        //init dropdownview
        mDropDownMenu.setDropDownMenu(Arrays.asList(headers), popupViews, contentView);
    }

代码不定时更新 https://github.com/chinaltz/JustAndroid

上一篇 下一篇

猜你喜欢

热点阅读