├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── FJMtSortButtonLib ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── fj │ │ └── mtsortbutton │ │ └── lib │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── fj │ │ │ └── mtsortbutton │ │ │ └── lib │ │ │ ├── DynamicSoreView.java │ │ │ ├── Interface │ │ │ ├── IDynamicSore.java │ │ │ └── ViewControl.java │ │ │ ├── SoreButton.java │ │ │ └── adapter │ │ │ └── ViewPagerAdapter.java │ └── res │ │ ├── drawable-xhdpi │ │ ├── radio_select.png │ │ └── radio_unselected.png │ │ ├── layout │ │ ├── anfq_sore_button.xml │ │ └── viewpager_default.xml │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── fj │ └── mtsortbutton │ └── lib │ └── ExampleUnitTest.java ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── fj │ │ └── mtsortbutton │ │ └── test │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── fj │ │ │ └── mtsortbutton │ │ │ └── test │ │ │ ├── IndexActivity.java │ │ │ ├── Main2Activity.java │ │ │ ├── MainActivity.java │ │ │ ├── adapter │ │ │ └── SortButtonAdapter.java │ │ │ └── model │ │ │ └── ButtonModel.java │ └── res │ │ ├── drawable-xhdpi │ │ ├── icon_1.png │ │ ├── icon_10.png │ │ ├── icon_11.png │ │ ├── icon_12.png │ │ ├── icon_13.png │ │ ├── icon_14.png │ │ ├── icon_15.png │ │ ├── icon_16.png │ │ ├── icon_17.png │ │ ├── icon_18.png │ │ ├── icon_19.png │ │ ├── icon_2.png │ │ ├── icon_20.png │ │ ├── icon_3.png │ │ ├── icon_4.png │ │ ├── icon_5.png │ │ ├── icon_6.png │ │ ├── icon_7.png │ │ ├── icon_8.png │ │ ├── icon_9.png │ │ ├── radio1.png │ │ └── radio2.png │ │ ├── layout │ │ ├── activity_index.xml │ │ ├── activity_main.xml │ │ ├── activity_main2.xml │ │ ├── item_button.xml │ │ ├── viewpager_page.xml │ │ └── viewpager_page_text.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── fj │ └── mtsortbutton │ └── test │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar']) 26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 27 | exclude group: 'com.android.support', module: 'support-annotations' 28 | }) 29 | compile 'com.android.support:appcompat-v7:25.1.1' 30 | testCompile 'junit:junit:4.12' 31 | } 32 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\Android_install\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/src/androidTest/java/fj/mtsortbutton/lib/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package fj.mtsortbutton.lib; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("fj.mtsortbutton.lib.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/src/main/java/fj/mtsortbutton/lib/DynamicSoreView.java: -------------------------------------------------------------------------------- 1 | package fj.mtsortbutton.lib; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.support.v4.view.ViewPager; 6 | import android.util.AttributeSet; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.widget.GridView; 10 | import android.widget.ImageView; 11 | import android.widget.LinearLayout; 12 | 13 | import java.util.ArrayList; 14 | import java.util.HashMap; 15 | import java.util.List; 16 | 17 | import fj.mtsortbutton.lib.Interface.IDynamicSore; 18 | import fj.mtsortbutton.lib.Interface.ViewControl; 19 | import fj.mtsortbutton.lib.adapter.ViewPagerAdapter; 20 | 21 | /** 22 | * @author FengTong 23 | * @date 2017/6/1 24 | */ 25 | public class DynamicSoreView extends LinearLayout { 26 | Context mContext; 27 | private ViewPager viewPager; 28 | private LinearLayout llIndicator; 29 | 30 | //选中点 31 | private int RadioSelect; 32 | //未选中点 33 | private int RadioUnselected; 34 | //圆点间距 35 | private int distance; 36 | //每页展示几个 37 | private int number; 38 | //展示数据的gridView 39 | private Integer gridView; 40 | //总页数 41 | private int page; 42 | //数据List 43 | private List dataList; 44 | 45 | List listSoreView = new ArrayList<>(); 46 | View soreView; 47 | 48 | 49 | //接口 50 | private IDynamicSore iDynamicSore; 51 | //设置接口 52 | public IDynamicSore getiDynamicSore() { 53 | return iDynamicSore; 54 | } 55 | 56 | public void setiDynamicSore(IDynamicSore iDynamicSore) { 57 | this.iDynamicSore = iDynamicSore; 58 | } 59 | 60 | public DynamicSoreView(Context context, AttributeSet attrs) { 61 | super(context, attrs); 62 | mContext = context; 63 | LayoutInflater.from(context).inflate(R.layout.anfq_sore_button, this, true); 64 | viewPager = (ViewPager) findViewById(R.id.viewPager); 65 | llIndicator = (LinearLayout) findViewById(R.id.llIndicator); 66 | 67 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DynamicSoreView); 68 | if (typedArray != null) { 69 | //选中点 70 | RadioSelect = typedArray.getResourceId(R.styleable.DynamicSoreView_SoreRadioSelect, R.drawable.radio_select); 71 | //未选中点 72 | RadioUnselected = typedArray.getResourceId(R.styleable.DynamicSoreView_SoreRadioUnselected, R.drawable.radio_unselected); 73 | //圆点间距 74 | distance = typedArray.getInteger(R.styleable.DynamicSoreView_SoreDistance,10); 75 | //每页显示几个 76 | number = typedArray.getInteger(R.styleable.DynamicSoreView_SoreNumber,8); 77 | typedArray.recycle(); 78 | } 79 | 80 | //设置空布局 81 | gridView = R.layout.viewpager_default; 82 | } 83 | 84 | //初始化ViewPager 85 | private void initViewPager(){ 86 | listSoreView = new ArrayList<>(); 87 | LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 88 | for (int i = 0; i < page; i++) { 89 | //循环拿到传入的View 90 | soreView = layoutInflater.inflate(gridView, null); 91 | //通过接口回掉的形式返回当前的View,实现接口后开源拿到每个View然后进行操作 92 | if (iDynamicSore!=null){ 93 | List data; 94 | int total = dataList.size(); 95 | if(i == page-1){ 96 | //添加按钮 97 | data = new ArrayList<>(); 98 | for(int j = i*number;j(); 103 | int size; 104 | if(total< number){ 105 | size = total; 106 | }else{ 107 | size = (i+1)*number; 108 | } 109 | for(int j = i*number;j t){ 198 | this.dataList = t; 199 | this.page = (int)Math.ceil((double) t.size()/number);//计算出有几页/这里用了ceil函数凑整,2.1=3 200 | initViewPager(); 201 | return this; 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/src/main/java/fj/mtsortbutton/lib/Interface/IDynamicSore.java: -------------------------------------------------------------------------------- 1 | package fj.mtsortbutton.lib.Interface; 2 | 3 | import android.view.View; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author FengTong 9 | * @date 2017/6/1 10 | */ 11 | public interface IDynamicSore { 12 | void setGridView(View view, int type, List data); 13 | } 14 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/src/main/java/fj/mtsortbutton/lib/Interface/ViewControl.java: -------------------------------------------------------------------------------- 1 | package fj.mtsortbutton.lib.Interface; 2 | 3 | import android.view.View; 4 | 5 | public interface ViewControl { 6 | void setView(View view, int type); 7 | } 8 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/src/main/java/fj/mtsortbutton/lib/SoreButton.java: -------------------------------------------------------------------------------- 1 | package fj.mtsortbutton.lib; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.support.v4.view.ViewPager; 6 | import android.util.AttributeSet; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.widget.ImageView; 10 | import android.widget.LinearLayout; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | import fj.mtsortbutton.lib.Interface.ViewControl; 16 | import fj.mtsortbutton.lib.adapter.ViewPagerAdapter; 17 | 18 | 19 | public class SoreButton extends LinearLayout { 20 | Context mContext; 21 | private ViewPager viewPager; 22 | private LinearLayout llIndicator; 23 | //选中图片 24 | private int RadioSelect; 25 | //未选中图片 26 | private int RadioUnselected; 27 | //圆点间距 28 | private int distance; 29 | 30 | List listSoreView = new ArrayList<>(); 31 | View soreView; 32 | private List listView; 33 | 34 | //接口 35 | private ViewControl viewControl; 36 | //设置接口 37 | public void setViewControl(ViewControl viewControl) { 38 | this.viewControl = viewControl; 39 | } 40 | 41 | public SoreButton(Context context) { 42 | super(context); 43 | } 44 | 45 | public SoreButton(Context context, AttributeSet attrs) { 46 | super(context, attrs); 47 | mContext = context; 48 | LayoutInflater.from(context).inflate(R.layout.anfq_sore_button, this, true); 49 | viewPager = (ViewPager) findViewById(R.id.viewPager); 50 | llIndicator = (LinearLayout) findViewById(R.id.llIndicator); 51 | 52 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DynamicSoreView); 53 | if (typedArray != null) { 54 | //选中点 55 | RadioSelect = typedArray.getResourceId(R.styleable.DynamicSoreView_SoreRadioSelect, R.drawable.radio_select); 56 | //未选中点 57 | RadioUnselected = typedArray.getResourceId(R.styleable.DynamicSoreView_SoreRadioUnselected, R.drawable.radio_unselected); 58 | //圆点间距 59 | distance = typedArray.getInteger(R.styleable.DynamicSoreView_SoreDistance,10); 60 | typedArray.recycle(); 61 | } 62 | //设置空布局 63 | listView = new ArrayList<>(); 64 | listView.add(R.layout.viewpager_default); 65 | } 66 | 67 | //初始化ViewPager 68 | private void initViewPager(){ 69 | listSoreView = new ArrayList<>(); 70 | LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 71 | int size = listView.size(); 72 | for (int i = 0; i < size; i++) { 73 | //循环拿到传入的View 74 | soreView = layoutInflater.inflate(listView.get(i), null); 75 | //通过接口回掉的形式返回当前的View,实现接口后开源拿到每个View然后进行操作 76 | if (viewControl!=null){ 77 | viewControl.setView(soreView,i); 78 | } 79 | //将获取到的View添加到List中 80 | listSoreView.add(soreView); 81 | } 82 | //设置viewPager的Adapter 83 | viewPager.setAdapter(new ViewPagerAdapter(listSoreView)); 84 | //初始化LinearLayout,加入指示器 85 | initLinearLayout(viewPager, size, llIndicator); 86 | } 87 | 88 | /** 89 | * 设置指示器,设置ViewPager滑动事件监听 90 | * @param viewPager --ViewPager 91 | * @param pageSize --View的页数 92 | * @param linearLayout --LinearLayout 93 | */ 94 | private void initLinearLayout(ViewPager viewPager, int pageSize, LinearLayout linearLayout) { 95 | linearLayout.removeAllViews(); 96 | //定义数组放置指示器的点,pageSize是View个数 97 | final ImageView[] imageViews = new ImageView[pageSize]; 98 | for (int i = 0; i < pageSize; i++) { 99 | //创建ImageView 100 | ImageView image = new ImageView(mContext); 101 | //将ImageView放入数组 102 | imageViews[i] = image; 103 | //默认选中第一个 104 | if (i == 0) { 105 | //选中的点 106 | image.setImageResource(RadioSelect); 107 | } else { 108 | //未选中的点 109 | image.setImageResource(RadioUnselected); 110 | } 111 | //设置宽高 112 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( 113 | LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); 114 | params.setMargins(distance, 0, distance, 0); 115 | //将点添加到LinearLayout中 116 | linearLayout.addView(image, params); 117 | } 118 | 119 | //ViewPager的滑动事件 120 | viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { 121 | @Override 122 | public void onPageScrollStateChanged(int arg0) {} 123 | @Override 124 | public void onPageScrolled(int arg0, float arg1, int arg2) {} 125 | @Override 126 | public void onPageSelected(int arg0) { 127 | //arg0当前ViewPager 128 | for (int i = 0; i < imageViews.length; i++) { 129 | //设置为选中的点 130 | imageViews[arg0].setImageResource(RadioSelect); 131 | //判断当前的点i如果不等于当前页的话就设置为未选中 132 | if (arg0 != i) { 133 | imageViews[i].setImageResource(RadioUnselected); 134 | } 135 | } 136 | } 137 | }); 138 | } 139 | 140 | /** 141 | * 设置圆点距离 142 | * @param distance --距离 143 | * @return 144 | */ 145 | @Deprecated 146 | public SoreButton setDistance(int distance){ 147 | this.distance = distance; 148 | return this; 149 | } 150 | /** 151 | * 设置指示器图片 152 | * @param radioSelect --选中图片 153 | * @param radioUnselected --未选中图片 154 | * @return 155 | */ 156 | @Deprecated 157 | public SoreButton setIndicator(int radioSelect,int radioUnselected){ 158 | //选中图片 159 | RadioSelect = radioSelect; 160 | //未选中图片 161 | RadioUnselected = radioUnselected; 162 | return this; 163 | } 164 | /** 165 | * 设置view 166 | * @param listView --view 167 | * @return 168 | */ 169 | public SoreButton setView(List listView){ 170 | this.listView = listView; 171 | return this; 172 | } 173 | /** 174 | * 设置初始化 175 | */ 176 | public SoreButton init(){ 177 | initViewPager(); 178 | return this; 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/src/main/java/fj/mtsortbutton/lib/adapter/ViewPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package fj.mtsortbutton.lib.adapter; 2 | 3 | import android.support.v4.view.PagerAdapter; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | 7 | import java.util.List; 8 | 9 | public class ViewPagerAdapter extends PagerAdapter { 10 | 11 | private List views = null; 12 | 13 | public ViewPagerAdapter(List views) { 14 | this.views = views; 15 | } 16 | 17 | @Override 18 | public int getCount() { 19 | return views.size() > 0 ? views.size() : 0; 20 | } 21 | 22 | @Override 23 | public boolean isViewFromObject(View view, Object object) { 24 | return view == object; 25 | } 26 | 27 | @Override 28 | public Object instantiateItem(ViewGroup viewGroup, int i) { 29 | viewGroup.addView(views.get(i)); 30 | return views.get(i); 31 | } 32 | 33 | @Override 34 | public void destroyItem(ViewGroup viewGroup, int i, Object object) { 35 | viewGroup.removeView(views.get(i)); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/src/main/res/drawable-xhdpi/radio_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/FJMtSortButtonLib/src/main/res/drawable-xhdpi/radio_select.png -------------------------------------------------------------------------------- /FJMtSortButtonLib/src/main/res/drawable-xhdpi/radio_unselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/FJMtSortButtonLib/src/main/res/drawable-xhdpi/radio_unselected.png -------------------------------------------------------------------------------- /FJMtSortButtonLib/src/main/res/layout/anfq_sore_button.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/src/main/res/layout/viewpager_default.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | FJMtSortButtonLib 3 | 4 | -------------------------------------------------------------------------------- /FJMtSortButtonLib/src/test/java/fj/mtsortbutton/lib/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package fj.mtsortbutton.lib; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > ## 栗子——高仿美团首页分类按钮(更灵活) 2 | 3 | --- 4 | 5 | 6 | > ### 栗子惯例,先上GIF 7 | 8 | ![栗子.gif](http://upload-images.jianshu.io/upload_images/2071764-c9416063ff366935.gif) 9 | 10 | 11 | 12 | ## 使用姿势 13 | 14 | **引入(使用Gradle或者Maven)** 15 | 16 | 1)Gradle 17 | 18 | allprojects { 19 | repositories { 20 | ... 21 | maven { url 'https://jitpack.io' } 22 | } 23 | } 24 | dependencies { 25 | compile 'com.github.FJ917:FJMtSortButton:v1.1' 26 | } 27 | 2)Maven 28 | 29 | 30 | 31 | jitpack.io 32 | https://jitpack.io 33 | 34 | 35 | 36 | 37 | com.github.FJ917 38 | FJMtSortButton 39 | v1.1 40 | 41 | 42 | --- 43 | 44 | #### v1.1版本 45 | ## 新增自定义控件DynamicSoreView 46 | 实现通过服务器获取的数据,动态添加按钮,可以设置每页显示的个数。 47 | ## 使用方法 48 | 1)xml文件 49 | ``` 50 | 59 | ``` 60 | 2 )java 61 | ``` 62 | private void data(){ 63 | buttonList = setData();//模拟服务器获取到的按钮列表 64 | //设置界面监听 65 | dynamicSoreView.setiDynamicSore(this); 66 | //控件相关设置 67 | dynamicSoreView.setGridView(R.layout.viewpager_page).init(buttonList); 68 | } 69 | 70 | 71 | @Override 72 | public void setGridView(View view, final int type, List data) { 73 | List buttonModels= data; 74 | GridView gridView = (GridView) view.findViewById(R.id.gridView); 75 | dynamicSoreView.setNumColumns(gridView); 76 | SortButtonAdapter adapter = new SortButtonAdapter(this,buttonModels); 77 | gridView.setAdapter(adapter); 78 | gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 79 | @Override 80 | public void onItemClick(AdapterView parent, View view, int position, long id) { 81 | Toast.makeText(context,"第"+type+"页"+position,Toast.LENGTH_LONG).show(); 82 | } 83 | }); 84 | } 85 | ``` 86 | 87 | #### 说明:修改了1.0里的使用方式,但原来的也可以用,详细参考1.0使用方法 88 | --- 89 | 90 | #### v1.0版本 91 | 92 | ## 使用方法 93 | 94 | 1)xml文件 95 | ``` 96 | 97 | 102 | 103 | 111 | ``` 112 | 113 | 2)java文件 114 | 1.对自定义控件做一些设置 115 | 116 | //设置界面监听 117 | soreButton.setViewControl(this); 118 | //添加界面到list 119 | list = new ArrayList<>(); 120 | list.add(R.layout.viewpager_page); 121 | list.add(R.layout.viewpager_page); 122 | list.add(R.layout.viewpager_page_text); 123 | 124 | //控件相关设置 125 | //以前 126 | soreButton 127 | //设置选中和未选中指示器图标 128 | .setIndicator(R.drawable.radio1,R.drawable.radio2) 129 | //设置指示器半间距px 130 | .setDistance(10) 131 | //设置view组 132 | .setView(list) 133 | .init(); 134 | //修改(废弃了设置参数的方法,但是也可以用,只是建议在xml设置) 135 | soreButton.setView(list).init(); 136 | 将layout的布局add进去list中,然后调用setView方法把list传过去, 137 | 还提供了设置指示器图标的方法,以及指示器间距的方法,最后必须调用初始化方法init进行初始化 138 | 139 | 140 | 这是其中的一个layout布局,其实这里可以添加任意布局文件进去,是不是比美团更灵活呢? 141 | `布局R.layout.viewpager_page` 142 | 143 | 144 | 149 | 150 | 160 | 161 | 162 | 163 | 2.设置soreButton监听事件(具体的可以参考GIt里面的Demo) 164 | 165 | public class MainActivity extends AppCompatActivity implements ViewControl { 166 | 167 | private SoreButton soreButton; 168 | @Override 169 | protected void onCreate(Bundle savedInstanceState) { 170 | super.onCreate(savedInstanceState); 171 | setContentView(R.layout.activity_main); 172 | soreButton = (SoreButton) findViewById(R.id.soreButton); 173 | 174 | soreButton.setViewControl(this); 175 | } 176 | 177 | @Override 178 | public void setView(View view, final int type) { 179 | //这里会返回前面设置进去的View及对应的type,然后就可以进行操作了 180 | } 181 | } 182 | 183 | **划重点:上面的list中可以传入任意layout布局,然后通过接口回掉拿到View。比美团更加灵活。** 184 | 185 | **[博客地址](http://www.jianshu.com/p/e1631a8fab68)** 186 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "fj.mtsortbutton.test" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.1.1' 28 | testCompile 'junit:junit:4.12' 29 | compile project(':FJMtSortButtonLib') 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\Android_install\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/fj/mtsortbutton/test/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package fj.mtsortbutton.test; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("fj.mtsortbutton.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/fj/mtsortbutton/test/IndexActivity.java: -------------------------------------------------------------------------------- 1 | package fj.mtsortbutton.test; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.Button; 8 | 9 | public class IndexActivity extends AppCompatActivity implements View.OnClickListener{ 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | setContentView(R.layout.activity_index); 15 | findViewById(R.id.btn1).setOnClickListener(this); 16 | findViewById(R.id.btn2).setOnClickListener(this); 17 | } 18 | 19 | @Override 20 | public void onClick(View v) { 21 | switch (v.getId()){ 22 | case R.id.btn1: 23 | startActivity(new Intent(this,MainActivity.class)); 24 | break; 25 | case R.id.btn2: 26 | startActivity(new Intent(this,Main2Activity.class)); 27 | break; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/fj/mtsortbutton/test/Main2Activity.java: -------------------------------------------------------------------------------- 1 | package fj.mtsortbutton.test; 2 | 3 | import android.content.Context; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.AdapterView; 8 | import android.widget.Button; 9 | import android.widget.GridView; 10 | import android.widget.Toast; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | import fj.mtsortbutton.lib.DynamicSoreView; 16 | import fj.mtsortbutton.lib.Interface.IDynamicSore; 17 | import fj.mtsortbutton.test.adapter.SortButtonAdapter; 18 | import fj.mtsortbutton.test.model.ButtonModel; 19 | 20 | public class Main2Activity extends AppCompatActivity implements IDynamicSore { 21 | 22 | private Context context; 23 | private DynamicSoreView dynamicSoreView; 24 | private List list; 25 | 26 | List buttonList; 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_main2); 31 | context = this; 32 | dynamicSoreView = (DynamicSoreView) findViewById(R.id.dynamicSoreView); 33 | 34 | data(); 35 | Button button = (Button) findViewById(R.id.btn); 36 | button.setOnClickListener(new View.OnClickListener() { 37 | @Override 38 | public void onClick(View v) { 39 | data(); 40 | } 41 | }); 42 | } 43 | 44 | private void data(){ 45 | buttonList = setData();//模拟服务器获取到的按钮列表 46 | //设置界面监听 47 | dynamicSoreView.setiDynamicSore(this); 48 | //控件相关设置 49 | dynamicSoreView.setGridView(R.layout.viewpager_page).init(buttonList); 50 | } 51 | 52 | 53 | @Override 54 | public void setGridView(View view, final int type, List data) { 55 | List buttonModels= data; 56 | GridView gridView = (GridView) view.findViewById(R.id.gridView); 57 | dynamicSoreView.setNumColumns(gridView); 58 | SortButtonAdapter adapter = new SortButtonAdapter(this,buttonModels); 59 | gridView.setAdapter(adapter); 60 | gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 61 | @Override 62 | public void onItemClick(AdapterView parent, View view, int position, long id) { 63 | Toast.makeText(context,"第"+type+"页"+position,Toast.LENGTH_LONG).show(); 64 | } 65 | }); 66 | } 67 | 68 | private List setData(){ 69 | List data = new ArrayList<>(); 70 | ButtonModel buttonModel = new ButtonModel(); 71 | buttonModel.setDrawableIcon(R.drawable.icon_1); 72 | buttonModel.setName("美食"); 73 | data.add(buttonModel); 74 | 75 | buttonModel = new ButtonModel(); 76 | buttonModel.setDrawableIcon(R.drawable.icon_2); 77 | buttonModel.setName("电影"); 78 | data.add(buttonModel); 79 | buttonModel = new ButtonModel(); 80 | buttonModel.setDrawableIcon(R.drawable.icon_3); 81 | buttonModel.setName("酒店"); 82 | data.add(buttonModel); 83 | buttonModel = new ButtonModel(); 84 | buttonModel.setDrawableIcon(R.drawable.icon_4); 85 | buttonModel.setName("休闲娱乐"); 86 | data.add(buttonModel); 87 | buttonModel = new ButtonModel(); 88 | buttonModel.setDrawableIcon(R.drawable.icon_5); 89 | buttonModel.setName("外卖"); 90 | data.add(buttonModel); 91 | buttonModel = new ButtonModel(); 92 | buttonModel.setDrawableIcon(R.drawable.icon_6); 93 | buttonModel.setName("机票/火车票"); 94 | data.add(buttonModel); 95 | buttonModel = new ButtonModel(); 96 | buttonModel.setDrawableIcon(R.drawable.icon_7); 97 | buttonModel.setName("KTV"); 98 | data.add(buttonModel); 99 | buttonModel = new ButtonModel(); 100 | buttonModel.setDrawableIcon(R.drawable.icon_8); 101 | buttonModel.setName("周边游"); 102 | data.add(buttonModel); 103 | buttonModel = new ButtonModel(); 104 | buttonModel.setDrawableIcon(R.drawable.icon_9); 105 | buttonModel.setName("丽人"); 106 | data.add(buttonModel); 107 | buttonModel = new ButtonModel(); 108 | buttonModel.setDrawableIcon(R.drawable.icon_10); 109 | buttonModel.setName("旅游出行"); 110 | data.add(buttonModel); 111 | 112 | buttonModel = new ButtonModel(); 113 | buttonModel.setDrawableIcon(R.drawable.icon_11); 114 | buttonModel.setName("品质酒店"); 115 | data.add(buttonModel); 116 | buttonModel = new ButtonModel(); 117 | buttonModel.setDrawableIcon(R.drawable.icon_12); 118 | buttonModel.setName("生活服务"); 119 | data.add(buttonModel); 120 | buttonModel = new ButtonModel(); 121 | buttonModel.setDrawableIcon(R.drawable.icon_13); 122 | buttonModel.setName("足疗按摩"); 123 | data.add(buttonModel); 124 | buttonModel = new ButtonModel(); 125 | buttonModel.setDrawableIcon(R.drawable.icon_14); 126 | buttonModel.setName("母婴亲子"); 127 | data.add(buttonModel); 128 | buttonModel = new ButtonModel(); 129 | buttonModel.setDrawableIcon(R.drawable.icon_15); 130 | buttonModel.setName("结婚"); 131 | data.add(buttonModel); 132 | buttonModel = new ButtonModel(); 133 | buttonModel.setDrawableIcon(R.drawable.icon_16); 134 | buttonModel.setName("景点"); 135 | data.add(buttonModel); 136 | buttonModel = new ButtonModel(); 137 | buttonModel.setDrawableIcon(R.drawable.icon_17); 138 | buttonModel.setName("温泉"); 139 | data.add(buttonModel); 140 | buttonModel = new ButtonModel(); 141 | buttonModel.setDrawableIcon(R.drawable.icon_18); 142 | buttonModel.setName("学习培训"); 143 | data.add(buttonModel); 144 | buttonModel = new ButtonModel(); 145 | buttonModel.setDrawableIcon(R.drawable.icon_19); 146 | buttonModel.setName("洗浴/汗蒸"); 147 | data.add(buttonModel); 148 | buttonModel = new ButtonModel(); 149 | buttonModel.setDrawableIcon(R.drawable.icon_20); 150 | buttonModel.setName("全部分类"); 151 | data.add(buttonModel); 152 | return data; 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /app/src/main/java/fj/mtsortbutton/test/MainActivity.java: -------------------------------------------------------------------------------- 1 | package fj.mtsortbutton.test; 2 | 3 | import android.content.Context; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.AdapterView; 8 | import android.widget.GridView; 9 | import android.widget.TextView; 10 | import android.widget.Toast; 11 | 12 | import java.util.ArrayList; 13 | import java.util.HashMap; 14 | import java.util.List; 15 | 16 | import fj.mtsortbutton.lib.Interface.ViewControl; 17 | import fj.mtsortbutton.lib.SoreButton; 18 | import fj.mtsortbutton.test.adapter.SortButtonAdapter; 19 | import fj.mtsortbutton.test.model.ButtonModel; 20 | 21 | public class MainActivity extends AppCompatActivity implements ViewControl { 22 | 23 | private Context context; 24 | private SoreButton soreButton; 25 | private List list; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_main); 31 | context = this; 32 | soreButton = (SoreButton) findViewById(R.id.soreButton); 33 | 34 | //设置界面监听 35 | soreButton.setViewControl(this); 36 | //添加界面到list 37 | list = new ArrayList<>(); 38 | list.add(R.layout.viewpager_page); 39 | list.add(R.layout.viewpager_page); 40 | list.add(R.layout.viewpager_page_text); 41 | 42 | //控件相关设置 43 | // soreButton 44 | // //设置选中和未选中指示器图标 45 | // .setIndicator(R.drawable.radio1,R.drawable.radio2) 46 | // //设置指示器半间距px 47 | // .setDistance(10) 48 | // //设置view组 49 | // .setView(list) 50 | // .init(); 51 | soreButton.setView(list).init(); 52 | } 53 | 54 | @Override 55 | public void setView(View view, final int type) { 56 | switch (type) { 57 | case 0://第一个界面 58 | GridView gridView = (GridView) view.findViewById(R.id.gridView); 59 | SortButtonAdapter adapter = new SortButtonAdapter(this,setData()); 60 | gridView.setAdapter(adapter); 61 | gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 62 | @Override 63 | public void onItemClick(AdapterView parent, View view, int position, long id) { 64 | Toast.makeText(context,"第"+type+"页"+position,Toast.LENGTH_LONG).show(); 65 | } 66 | }); 67 | break; 68 | case 1://第二个界面 69 | GridView gridView2 = (GridView) view.findViewById(R.id.gridView); 70 | SortButtonAdapter adapter2 = new SortButtonAdapter(this,setData2()); 71 | gridView2.setAdapter(adapter2); 72 | gridView2.setOnItemClickListener(new AdapterView.OnItemClickListener() { 73 | @Override 74 | public void onItemClick(AdapterView parent, View view, int position, long id) { 75 | Toast.makeText(context,"第"+type+"页"+position,Toast.LENGTH_LONG).show(); 76 | } 77 | }); 78 | break; 79 | case 2://第三个界面 80 | TextView tvTitle = (TextView) view.findViewById(R.id.tvTitle); 81 | tvTitle.setText("可高度定制,可设置任意layout,并且在回调中获取该layout内的所有控件"); 82 | tvTitle.setOnClickListener(new View.OnClickListener() { 83 | @Override 84 | public void onClick(View v) { 85 | Toast.makeText(context,"点击了该文字",Toast.LENGTH_LONG).show(); 86 | } 87 | }); 88 | break; 89 | } 90 | } 91 | 92 | private List setData(){ 93 | List data = new ArrayList<>(); 94 | ButtonModel buttonModel = new ButtonModel(); 95 | buttonModel.setDrawableIcon(R.drawable.icon_1); 96 | buttonModel.setName("美食"); 97 | data.add(buttonModel); 98 | 99 | buttonModel = new ButtonModel(); 100 | buttonModel.setDrawableIcon(R.drawable.icon_2); 101 | buttonModel.setName("电影"); 102 | data.add(buttonModel); 103 | buttonModel = new ButtonModel(); 104 | buttonModel.setDrawableIcon(R.drawable.icon_3); 105 | buttonModel.setName("酒店"); 106 | data.add(buttonModel); 107 | buttonModel = new ButtonModel(); 108 | buttonModel.setDrawableIcon(R.drawable.icon_4); 109 | buttonModel.setName("休闲娱乐"); 110 | data.add(buttonModel); 111 | buttonModel = new ButtonModel(); 112 | buttonModel.setDrawableIcon(R.drawable.icon_5); 113 | buttonModel.setName("外卖"); 114 | data.add(buttonModel); 115 | buttonModel = new ButtonModel(); 116 | buttonModel.setDrawableIcon(R.drawable.icon_6); 117 | buttonModel.setName("机票/火车票"); 118 | data.add(buttonModel); 119 | buttonModel = new ButtonModel(); 120 | buttonModel.setDrawableIcon(R.drawable.icon_7); 121 | buttonModel.setName("KTV"); 122 | data.add(buttonModel); 123 | buttonModel = new ButtonModel(); 124 | buttonModel.setDrawableIcon(R.drawable.icon_8); 125 | buttonModel.setName("周边游"); 126 | data.add(buttonModel); 127 | buttonModel = new ButtonModel(); 128 | buttonModel.setDrawableIcon(R.drawable.icon_9); 129 | buttonModel.setName("丽人"); 130 | data.add(buttonModel); 131 | buttonModel = new ButtonModel(); 132 | buttonModel.setDrawableIcon(R.drawable.icon_10); 133 | buttonModel.setName("旅游出行"); 134 | data.add(buttonModel); 135 | return data; 136 | } 137 | 138 | private List setData2(){ 139 | List data = new ArrayList<>(); 140 | ButtonModel buttonModel = new ButtonModel(); 141 | buttonModel.setDrawableIcon(R.drawable.icon_11); 142 | buttonModel.setName("品质酒店"); 143 | data.add(buttonModel); 144 | buttonModel = new ButtonModel(); 145 | buttonModel.setDrawableIcon(R.drawable.icon_12); 146 | buttonModel.setName("生活服务"); 147 | data.add(buttonModel); 148 | buttonModel = new ButtonModel(); 149 | buttonModel.setDrawableIcon(R.drawable.icon_13); 150 | buttonModel.setName("足疗按摩"); 151 | data.add(buttonModel); 152 | buttonModel = new ButtonModel(); 153 | buttonModel.setDrawableIcon(R.drawable.icon_14); 154 | buttonModel.setName("母婴亲子"); 155 | data.add(buttonModel); 156 | buttonModel = new ButtonModel(); 157 | buttonModel.setDrawableIcon(R.drawable.icon_15); 158 | buttonModel.setName("结婚"); 159 | data.add(buttonModel); 160 | buttonModel = new ButtonModel(); 161 | buttonModel.setDrawableIcon(R.drawable.icon_16); 162 | buttonModel.setName("景点"); 163 | data.add(buttonModel); 164 | buttonModel = new ButtonModel(); 165 | buttonModel.setDrawableIcon(R.drawable.icon_17); 166 | buttonModel.setName("温泉"); 167 | data.add(buttonModel); 168 | buttonModel = new ButtonModel(); 169 | buttonModel.setDrawableIcon(R.drawable.icon_18); 170 | buttonModel.setName("学习培训"); 171 | data.add(buttonModel); 172 | buttonModel = new ButtonModel(); 173 | buttonModel.setDrawableIcon(R.drawable.icon_19); 174 | buttonModel.setName("洗浴/汗蒸"); 175 | data.add(buttonModel); 176 | buttonModel = new ButtonModel(); 177 | buttonModel.setDrawableIcon(R.drawable.icon_20); 178 | buttonModel.setName("全部分类"); 179 | data.add(buttonModel); 180 | return data; 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /app/src/main/java/fj/mtsortbutton/test/adapter/SortButtonAdapter.java: -------------------------------------------------------------------------------- 1 | package fj.mtsortbutton.test.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import java.util.List; 12 | 13 | import fj.mtsortbutton.test.R; 14 | import fj.mtsortbutton.test.model.ButtonModel; 15 | 16 | public class SortButtonAdapter extends BaseAdapter { 17 | private Context mContext; 18 | private LayoutInflater inflater; 19 | private List data; 20 | public SortButtonAdapter(Context context, List data) { 21 | this.mContext = context; 22 | this.inflater = LayoutInflater.from(context); 23 | this.data = data; 24 | } 25 | 26 | @Override 27 | public int getCount() { 28 | return data.size(); 29 | } 30 | 31 | @Override 32 | public Object getItem(int position) { 33 | return position; 34 | } 35 | 36 | @Override 37 | public long getItemId(int position) { 38 | return position; 39 | } 40 | 41 | @Override 42 | public View getView(int position, View view, ViewGroup parent) { 43 | ViewHolder holder; 44 | if (null == view) { 45 | view = inflater.inflate(R.layout.item_button, null); 46 | holder = new ViewHolder(); 47 | holder.icon = (ImageView) view.findViewById(R.id.icon); 48 | holder.name = (TextView) view.findViewById(R.id.name); 49 | view.setTag(holder); 50 | } else { 51 | holder = (ViewHolder) view.getTag(); 52 | } 53 | holder.name.setText(data.get(position).getName()); 54 | holder.icon.setImageResource(data.get(position).getDrawableIcon()); 55 | return view; 56 | } 57 | class ViewHolder { 58 | ImageView icon; 59 | TextView name; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/fj/mtsortbutton/test/model/ButtonModel.java: -------------------------------------------------------------------------------- 1 | package fj.mtsortbutton.test.model; 2 | 3 | /** 4 | * @author FengTong 5 | * @date 2017/6/1 6 | */ 7 | public class ButtonModel { 8 | private int id; 9 | private int drawableIcon; 10 | private String urlIcon; 11 | private String name; 12 | 13 | public int getId() { 14 | return id; 15 | } 16 | 17 | public void setId(int id) { 18 | this.id = id; 19 | } 20 | 21 | public int getDrawableIcon() { 22 | return drawableIcon; 23 | } 24 | 25 | public void setDrawableIcon(int drawableIcon) { 26 | this.drawableIcon = drawableIcon; 27 | } 28 | 29 | public String getUrlIcon() { 30 | return urlIcon; 31 | } 32 | 33 | public void setUrlIcon(String urlIcon) { 34 | this.urlIcon = urlIcon; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_1.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_10.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_11.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_12.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_13.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_14.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_15.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_16.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_17.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_18.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_19.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_2.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_20.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_3.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_4.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_5.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_6.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_7.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_8.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/icon_9.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/radio1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/radio1.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/radio2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FJ917/FJMtSortButton/64620c5386efb1c0f579ffdca78406aa8648bf02/app/src/main/res/drawable-xhdpi/radio2.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_index.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 |