All Projects → RobertApikyan → Segmentedcontrol

RobertApikyan / Segmentedcontrol

Licence: apache-2.0
Android SegmentedControl + multi row support

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Segmentedcontrol

Xamarin.gradlebindings
VS add-in. Creates Xamarin.Android Binding Projects using gradle
Stars: ✭ 136 (-4.9%)
Mutual labels:  gradle
Flutter Tiktok Ui Api Clone
Flutter Tiktok UI API Clone
Stars: ✭ 139 (-2.8%)
Mutual labels:  demo
Aspnetcore Angular Ngrx
🚀 An ASP.NET Core WebAPI Demo with an Angular Client using Ngrx store and effects and Signalr
Stars: ✭ 141 (-1.4%)
Mutual labels:  demo
Kotlinx Benchmark
Kotlin multiplatform benchmarking toolkit
Stars: ✭ 137 (-4.2%)
Mutual labels:  gradle
Demos
demos 一个简洁的web开发编辑器
Stars: ✭ 138 (-3.5%)
Mutual labels:  demo
Java Ddd Skeleton
♨️ DDD in Java skeleton & examples. Course:
Stars: ✭ 140 (-2.1%)
Mutual labels:  gradle
Golang For Nodejs Developers
Examples of Golang compared to Node.js for learning
Stars: ✭ 2,698 (+1786.71%)
Mutual labels:  demo
Laravel Scaffold
The base for developing awesome projects
Stars: ✭ 142 (-0.7%)
Mutual labels:  demo
Javafbp
Java Implementation of Flow-Based Programming (FBP)
Stars: ✭ 138 (-3.5%)
Mutual labels:  gradle
Interactive Repulsive Effect
🍫 An interactive repulsion effect of grid items as seen in BestServedBold's Dribbble shot "Holographic-Interactions".
Stars: ✭ 141 (-1.4%)
Mutual labels:  demo
Kaetram Open
An open-source 2D HTML5 adventure based off BrowserQuest (BQ).
Stars: ✭ 138 (-3.5%)
Mutual labels:  demo
Android Development Aircraft Carrier
打造安卓开发航空母舰,Android Studio 使用集锦
Stars: ✭ 138 (-3.5%)
Mutual labels:  gradle
Tcb Demo Basic
小程序·云开发系列教程——基础能力DEMO
Stars: ✭ 140 (-2.1%)
Mutual labels:  demo
Nice Knowledge System
📚不积跬步无以至千里,每天进步一点点,Passion,Self-regulation,Love and Share
Stars: ✭ 137 (-4.2%)
Mutual labels:  gradle
Kotlin Gradle Plugin Template
🐘 A template to let you started with custom Gradle Plugins + Kotlin in a few seconds
Stars: ✭ 141 (-1.4%)
Mutual labels:  gradle
Spring Boot Demo
Spring Boot的基础教程,由浅入深,一步一步学习Spring Boot,最后学到的不单单是基础!Spring Cloud基础教程请看:https://github.com/roncoo/spring-cloud-demo
Stars: ✭ 1,687 (+1079.72%)
Mutual labels:  demo
Tyrian
Full-featured TypeScript on JVM
Stars: ✭ 138 (-3.5%)
Mutual labels:  gradle
Lockdemo
指纹识别、图形识别、aliOCR识别
Stars: ✭ 142 (-0.7%)
Mutual labels:  demo
Frontend Download Sample
🎄 自己整理的一些项目中遇到过的关于上传和下载的一些Demo,仅供给位看官参考,避免踩坑,即插即用,欢迎fork和star🌟,为这个仓库添砖加瓦~(P.S. 个人认为如果没写过上传下载其实还是挺麻烦的~)
Stars: ✭ 142 (-0.7%)
Mutual labels:  demo
27daysofcode
A repo with small projects
Stars: ✭ 140 (-2.1%)
Mutual labels:  demo

Android SegmentedControl + multi row support + multi selection

minSdk API 14+

N|Solid

Demo App, Play store link

Or try demo App online !

License

Segmented control for Android, with a lot of customization properties

ScreenShots

Download

Gradle

Add to project level build.gradle

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Add dependency to app module level build.gradle

dependencies {
    implementation 'com.github.RobertApikyan:SegmentedControl:1.2.0'
}

Maven

<repositories>
	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>
</repositories>

Add dependency

<dependency>
    <groupId>com.github.RobertApikyan</groupId>
    <artifactId>SegmentedControl</artifactId>
    <version>1.1.3</version>
</dependency>

Done.

Simple usage in XML

<segmented_control.widget.custom.android.com.segmentedcontrol.SegmentedControl
                android:id="@+id/segmented_control"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="8dp"
                app:columnCount="3"				       
                app:distributeEvenly="true"
                app:textVerticalPadding="6dp"
                app:radius="12dp"
                app:segments="@array/your_array_data" />

Attributes

     <attr name="supportedSelectionsCount" format="boolean" /> setSupportedSelectionsCount(int)
     <attr name="reselectionEnabled" format="boolean" /> setDistributeEvenly(boolean)
     <attr name="distributeEvenly" format="boolean" /> setDistributeEvenly(boolean)
     <attr name="columnCount" format="integer" /> setColumnCount(int)
     <attr name="segments" format="reference" /> addSegments(Object[]), addSegments(List)
     <attr name="selectedStrokeColor" format="color" /> setSelectedStrokeColor(int)
     <attr name="unSelectedStrokeColor" format="color" /> setUnSelectedStrokeColor(int)
     <attr name="strokeWidth" format="dimension" / setStrokeWidth(int)
     <attr name="selectedBackgroundColor" format="color" /> setSelectedBackgroundColor(int)
     <attr name="unSelectedBackgroundColor" format="color" /> setUnSelectedBackgroundColor(int)
     <attr name="selectedTextColor" format="color"/> setSelectedTextColor(int)
     <attr name="unSelectedTextColor" format="color"/> setUnSelectedTextColor(int)
     <attr name="textSize" format="dimension"/> setTextSize(int)
     <attr name="selectionAnimationDuration" format="integer"/>
     <attr name="focusedBackgroundColor" format="color"/>
     <attr name="textHorizontalPadding" format="dimension"/> setTextHorizontalPadding(int)
     <attr name="textVerticalPadding" format="dimension"/> setTextVerticalPadding(int)
     <attr name="segmentVerticalMargin" format="dimension"/> setSegmentVerticalMargin(int)
     <attr name="segmentHorizontalMargin" format="dimension"/> setSegmentHorizontalMargin(int)
     <attr name="radius" format="dimension"/> setRadius(int)
     <attr name="topLeftRadius" format="dimension"/> setTopLeftRadius(int)
     <attr name="topRightRadius" format="dimension"/> setTopRightRadius(int)
     <attr name="bottomRightRadius" format="dimension"/> setBottomRightRadius(int)
     <attr name="bottomLeftRadius" format="dimension"/> setBottomLeftRadius(int)
     <attr name="radiusForEverySegment" format="boolean"/> setRadiusForEverySegment(boolean)
     <attr name="fontAssetPath" format="string"/>  setTypeFace(TypeFace)

Note: After every configuration change call segmentedControl.notifyConfigIsChanged() method

Example

        segmentedControl.setStrokeWidth(width.intValue());
        segmentedControl.setColumnCount(columnCount);
        segmentedControl.notifyConfigIsChanged();

SegmentedControl uses SegmentAdapter and SegmentViewHolder for displaying segments. There are allready exist a default implementations for SegmentAdapter (SegmentAdapterImpl) and SegmentViewHolder (SegmentViewHolderImpl), but if you want to make your custom implementation... well here is the steps

  1. Define segment_item.xml inside layouts folder

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <TextView
            android:id="@+id/text_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_margin="2dp"
            android:background="@color/colorPrimary"
            android:gravity="center"
            android:textColor="@color/colorAccent"
            android:textSize="14sp" />
    </LinearLayout>
    
  2. Create a SegmentViewHolder instance (AppSegmentViewHolder) (here I define the segment generic data type as a String)

    public class AppSegmentViewHolder extends SegmentViewHolder<String> {
        TextView textView;
    
        public AppSegmentViewHolder(@NonNull View sectionView) {
            super(sectionView);
            textView = (TextView) sectionView.findViewById(R.id.text_view);
        }
    
        @Override
        protected void onSegmentBind(String segmentData) {
            textView.setText(segmentData);
        }
    }
    
  3. Create a SegmentAdapter instance

    public class AppSegmentAdapter extends SegmentAdapter<String, AppSegmentViewHolder> {
    
        @NonNull
        @Override
        protected AppSegmentViewHolder onCreateViewHolder(@NonNull LayoutInflater layoutInflater, ViewGroup viewGroup, int i) {
            return new AppSegmentViewHolder(layoutInflater.inflate(R.layout.item_segment, null));
        }
    }
    
  4. Pass the adapter to the segmentedControl

    segmentedControl = (SegmentedControl) findViewById(R.id.segmented_control);
    segmentedControl.setAdapter(new AppSegmentAdapter());
    
  5. Finally add segments data.

    segmentedControl.addSegments(getResources().getStringArray(R.array.segments));
    

That's it :)

For custom implementation use SegmentedControlUtils helper class in order to define segment background type and background radius.

View Robert Apikyan profile on LinkedIn

License

Copyright 2017 Robert Apikyan

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].