GithubHelp home page GithubHelp logo

spacetablayout's Introduction

Not actively maintained, but PRs are welcomed

Synopsis

This is a custom implementation of a RelativeLayout that you can use along with a ViewPager to navigate between fragments.

alt text alt text alt text

Code usage

You can use this properties in xml for convenience. You can set the number of tabs you want to use and the starting tab position.

        app:number_of_tabs="five"
        app:starting_position="three"
        
        app:tab_color="@color/colorPrimary"
        app:button_color="@color/colorAccent"
        app:text_color="#61FFFFFF"
        
        app:icon_one="@drawable/ic_hotel_black_24dp"
        app:icon_two="@drawable/design_ic_visibility"
        app:icon_three="@drawable/ic_content_cut_black_24dp"
        app:icon_four="@drawable/ic_check_black_24dp"
        app:icon_five="@drawable/ic_fingerprint_black_24dp"
         
        app:text_one="Action"
        app:text_two="Action"
        app:text_three="Action"

You can also use the fallowing methods to customize its appearance and behavior:

Method Description
getTabLayout(); Gives you the base RelativeLayout.
setTabColor(@ColorInt int backgroundColor); Change the color of the Tab.
getCurrentPosition(); Gives you the current tab position.
getButton(); Give you the Floating Action Button View.
setButtonColor(@ColorInt int backgroundColor); Change the color of the Floating Button.
setOnClickListener(View.OnClickListener l); Set the same OnClickListener to all positions.
setTabOneOnClickListener(View.OnClickListener ll); Set the OnClickListener for the first position.
setTabTwoOnClickListener(View.OnClickListener cl); Set the OnClickListener for the second position.
getTabOneView(); Get you the first base LinearLayout that contains an ImageView or an ImageView and a TextView.
setTabOneView(View tabOneView); You can set the base layout for the first position.
getTabTwoView(); Get you the second base LinearLayout that contains an ImageView or an ImageView and a TextView.
setTabTwoView(View centerView); You can set the base layout for the second position.
setTabOneIcon(@DrawableRes int tabOneIcon); Set the icon for both the first tab and the Action Button when in the first position.
setTabTwoIcon(@DrawableRes int tabTwoIcon); Set the icon for both the second tab and the Action Button when in the second position.

Motivation

I get the inspiration from the Google Space app that uses a center Floating Action Button. I liked the idea so much that I though that it would be so nice if we could have this like a TabLayout.

You can see in the image:

alt text

Installation

Declaring dependencies

Add this to dependencies brackets in the gradle.build file:

compile 'eu.long1:spacetablayout:1.0.4'

XML implementation

In your layout just include this. You can customize the Tab here with text, icons, colors...

 <eu.long1.spacetablayout.SpaceTabLayout
        android:id="@+id/spaceTabLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        app:number_of_tabs="five"
        app:starting_position="three"
        app:tab_color="@color/colorPrimary"
        app:button_color="@color/colorAccent"
        app:text_color="#61FFFFFF"
        app:icon_one="@drawable/ic_hotel_black_24dp"
        app:icon_two="@drawable/design_ic_visibility"
        app:icon_three="@drawable/ic_content_cut_black_24dp"
        app:icon_four="@drawable/ic_check_black_24dp"
        app:icon_five="@drawable/ic_fingerprint_black_24dp"/>

SnackBar behavior

If you are using a CoordinatorLayout as the root of your layout you can add this line to proper handle the behavior when a SnackBar is visible.

 app:layout_behavior="eu.long1.spacetablayout.SpaceTabLayoutBehavior" 

XML Example

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="56dp" />

    <eu.long1.spacetablayout.SpaceTabLayout
        android:id="@+id/spaceTabLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_behavior="eu.long1.spacetablayout.SpaceTabLayoutBehavior"
        app:number_of_tabs="five"
        app:starting_position="three" />

</android.support.design.widget.CoordinatorLayout>

Code implementation

In your MainActivity.java you need to initialize the SpaceTabLayout like this:

    SpaceTabLayout tabLayout;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            //add the fragments you want to display in a List
            List<Fragment> fragmentList = new ArrayList<>();
            fragmentList.add(new FragmentA());
            fragmentList.add(new FragmentB());
            fragmentList.add(new FragmentC());
            
            ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
            tabLayout = (SpaceTabLayout) findViewById(R.id.spaceTabLayout);
            
            //we need the savedInstanceState to get the position
            tabLayout.initialize(viewPager, getSupportFragmentManager(), 
                            fragmentList, savedInstanceState);
        }
    
    
        //we need the outState to save the position
        @Override
        protected void onSaveInstanceState(Bundle outState) {
            tabLayout.saveState(outState);
            super.onSaveInstanceState(outState);
        }

Issues

If you have an issues with this library, please open a issue here: https://github.com/thelong1EU/SpaceTabLayout/issues and provide enough information to reproduce it. The following information needs to be provided:

  1. Which version of the SDK are you using?
  • What device are you using?
  • What steps will reproduce the problem?
  • Relevant logcat output.
  • Optional: Any screenshot(s) that demonstrate the issue.

License

Copyright (c) 2016 Lung Răzvan

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.

spacetablayout's People

Contributors

davideas avatar long1eu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spacetablayout's Issues

Fragment loading

Can the fragment be loaded on click? If i understand correctly all the tabs are loaded when you start the app.

starting_position doesn't seem to work

Iv'e tried the the basic sample code and did:
app:starting_position="one"

The starting position was the center anyway. Tried on LG G3 Android 6.0 stock ROM

I also noticed that if I have more than 3 tabs then the text disappears (I'm ignoring the other issue that was already reported with the text overlapping the icon)

Test with version 1.03 and 1.04

Change Tab position Programmatically

I want to change the tabs from an Activity. like in XML we have starting_position and that opens whichever position we want spaceTabLayout to be selected by-default, Can I implement this programmatically.

RTL support

hello my friend first of all thank you for this great library it is vary beautiful and fast but it has a problem with RTL support so if you can fix it as soon as possible i would be very grateful.

2 tabs?

Is there anyway to have less than three tabs? For what I'm working on I only need two.

Smoother snapping of button

I noticed that a user can not scroll to the exact position of the button on the underlying bar, this causes the button to snap abruptly to the final position when the user releases the touch event.

Three tab text possition

I have used three tabs with text. but text not aligned centre and it's looking not good.

screenshot_2018-07-07-10-43-56  #1

before above view, I had used only icon so third icon has too much space on right side. and ##it's look like.

screenshot_2018-07-07-10-56-09 1

Please help me to figure it out. I want centred title text or only three icons but an appropriate view.

setTabOneOnClickListener(View.OnClickListener ll) doesn't detect the first click

With this setting of the onclick listener:
`tabLayout.setTabTwoOnClickListener(new View.OnClickListener() {
@OverRide
public void onClick(View view) {
Toast.makeText(getContext(),"Hello!",Toast.LENGTH_SHORT).show();

        }
    });`

When you select the second tab the onclick doesn't execute. But when I click for second time with the second tab selected the onclick is executed.

Any idea??...

Four Tabs + Text

Hi there,
I really love your project since it looks very cool. However, I wonder if it is possible to support four tabs and text. I know there may not have enough space but what if the text are short?
Thanks for your help!

forcestop when theres a lib for ads

im a newbie in android developing and i really love this spacetablayout but keeping force stop when i use lib for ads i hope someone can help me to resolve this

How to check if tab is visible

I have animation in all the 3 tabs, but it only animates in the first tab.
Is there a way I can know which tab the user is currently viewing, and begin the animation when they swipe to it?

How to send data from Activity to Fragment?

MyActivity onCreate

Bundle bundle=new Bundle();
        bundle.putString("name", "From Activity");
        bundle.putInt("id", 4);
        FragmentA fragobjA = new FragmentA();
        fragobjA.setArguments(bundle);

and this FragmentA

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_a, container, false);
        Bundle bundle = this.getArguments();
        if (bundle != null) {
            nomor = bundle.getInt("id", 0);
            info= bundle.getString("name");

        }; 
        return rootView;
       
    } .....

error nomor and id value : null

Crash with PlaceAutocompleteListener after go from tab>3 to tab <3

hi! I need help to fix the following problem.

i create 5 tabs one of them with a map and autocompletetextfragment.

the map is in tab 2.

when I navigate between tabs 1 to 3 works fine

but when I go to tab 4 or 5 and return to one of the first ones crashes with the following error:
Binary XML file line #53: Duplicate id 0x7f0a0201, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.location.places.ui.PlaceAutocompleteFragment

can somebody helps me?

Change color of Button

Hi , my question is : can i change the color of the Button in each position ?

Ex ; position 1 = green 2= black 3 = white ...

Thanks

Cannot create more than 3 tabs

Hi, when I try to create more than three tabs, the text for fourth and onwards tabs doesn't show, moreover the icon is not changing for the fourth tab and onwards!!

Thanks.

tablayout initialize error after click other fragment then back to tablayout fragment

10-31 23:09:14.749 14194-14194/com.example.alfattah.absensiproject E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.alfattah.absensiproject, PID: 14194
java.lang.IllegalArgumentException: You have 3 tabs.
at eu.long1.spacetablayout.SpaceTabLayout.initialize(SpaceTabLayout.java:266)

and this my code :

public class DashboardFragment extends Fragment {

public DashboardFragment() {
    // Required empty public constructor
}

SpaceTabLayout tabLayout;
List<Fragment> fragmentList = new ArrayList<>();
CheckinFragment checkinFragment = new CheckinFragment();
MapsFragment mapsFragment = new MapsFragment();
CheckOutFragment checkOutFragment = new CheckOutFragment();
ViewPager dashboardViewpager;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View  view =  inflater.inflate(R.layout.fragment_dashboard, container, false);
    dashboardViewpager = view.findViewById(R.id.viewPagerdashboard);
    tabLayout = view.findViewById(R.id.spaceTabLayout);

    fragmentList.add(checkinFragment);
    fragmentList.add(mapsFragment);
    fragmentList.add(checkOutFragment);


    tabLayout.initialize(dashboardViewpager, getActivity().getSupportFragmentManager(), fragmentList, savedInstanceState);








    return view;
}

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
    tabLayout.saveState(outState);
    super.onSaveInstanceState(outState);

}

@Override
public void onStart() {
    super.onStart();

}

}

Calling onCreateView method

I get an error while clicking tab icons. the error is _android.view.InflateException: Binary XML file line #0: Error inflating class fragment_ . The error occurs when onCreateView method is called 2 times. I apply workaround using first creation check.

onclicklistener reacts at the 2-nd tap

Example:

tabLayout.setOnClickListener(new View.OnClickListener() {
@OverRide
public void onClick(View v) {
Toast.makeText(getApplication(), ""+tabLayout.getCurrentPosition(),Toast.LENGTH_SHORT).show();
}
});

the toast is shown when I tap the second time on an element

Use only texts

Hi,
Is it possible to remove all the icons and use only texts?

Tnks

Icons are big

Library working fine. I'm using this with 3 fragments but the unselected icons are too big.

problem with icon size

hi.icon are so big.i know we can change icon size with any editing software but i mean icon in unselected are so big and in selected ,are tiny.how we can control selected/unselected icon size

Add more tabs !!

Hello, nice TabLayout design, but can I easily add more tabs ?!

bug?

First of all, thank you for your work.
I'm a student and I'm making an app for college.
Everything was fine, but for a few days, I get the following error ... I do not know why ...

Thank you!!!

05-22 10:12:43.653 25307-25307/es.urjc.mov.vromero.spacetab E/AndroidRuntime: FATAL EXCEPTION: main
Process: es.urjc.mov.vromero.spacetab, PID: 25307
java.lang.RuntimeException: Unable to start activity ComponentInfo{es.urjc.mov.vromero.spacetab/es.urjc.mov.vromero.spacetab.MainActivity}: android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class eu.long1.spacetablayout.SpaceTabLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class eu.long1.spacetablayout.SpaceTabLayout
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class eu.long1.spacetablayout.SpaceTabLayout
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at es.urjc.mov.vromero.spacetab.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NoSuchFieldError: No field fab of type I in class Leu/long1/spacetablayout/R$id; or its superclasses (declaration of 'eu.long1.spacetablayout.R$id' appears in /data/app/es.urjc.mov.vromero.spacetab-1/split_lib_slice_3_apk.apk)
at eu.long1.spacetablayout.SpaceTabLayout.init(SpaceTabLayout.java:143)
at eu.long1.spacetablayout.SpaceTabLayout.(SpaceTabLayout.java:122)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
at android.view.LayoutInflater.createView(LayoutInflater.java:645) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:377) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
at es.urjc.mov.vromero.spacetab.MainActivity.onCreate(MainActivity.java:20) 
at android.app.Activity.performCreate(Activity.java:6679) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

Fragment and icon cannot be set dynamically

<eu.long1.spacetablayout.SpaceTabLayout
android:id="@+id/spaceTabLayout"
android:layout_width="match_parent"
android:layout_height="77dp"
android:layout_alignParentBottom="true"
android:gravity="bottom"
app:button_color="@color/colorAccent"
app:icon_five="@drawable/ic_ico_my"
app:icon_four="@drawable/design_ic_visibility"
app:icon_one="@drawable/ic_ico_home"
app:icon_three="@drawable/ic_ico_publish"
app:icon_two="@drawable/ic_ico_circle"
app:number_of_tabs="five"
app:starting_position="one"
app:layout_behavior="eu.long1.spacetablayout.SpaceTabLayoutBehavior"
app:tab_color="@color/colorPrimary"
app:text_color="#61FFFFFF" />

fragmentList.add(new HomeThis());
fragmentList.add(new Forum());
fragmentList.add(new Follow());
fragmentList.add(new Find());
fragmentList.add(new My_putstr());
spaceTabLayout.initialize(main_viewpager, getSupportFragmentManager(),
fragmentList, savedInstanceState);

You can only use XML to set icons,
spaceTabLayout.setTabOneIcon(R.drawable.ic_ico_home);
It will be a mistake
Prompt to reference null

Disable tabs onclick

Hi
How to disable on tab click? I don't want to navigate between fragments by click

thanks in advance

why RTL

hello , why when install on mobile be RTL and Totally be Messed up
two run , an genymotion true , an mobile false
capture11
screenshot_ - - - - -

Hiding Text

15497713_1227404344019428_120573064_n

unable to mask background Text when app started. after clicking it works fine. please suggest some fix

spaceTabLayout initialize issue in kotlin and how use spaceTabLayout in kotlin

val fragmentList = ArrayList()
fragmentList.add(HomeFragment.newInstance())
fragmentList.add(HomeFragment.newInstance())
fragmentList.add(HomeFragment.newInstance())
fragmentList.add(HomeFragment.newInstance())
fragmentList.add(HomeFragment.newInstance())

    val adapter = HomeTabAdapter(this, supportFragmentManager, 5)
    binding.viewPager!!.adapter = adapter
    binding.spaceTabLayout.initialize(binding.viewPager,getSupportFragmentManager(),fragmentList,savedInstanceState)

java.lang.IllegalArgumentException: No view found for id 0x7f080102 (com.nuatransmedia.sliver_spoon:id/viewPager) for fragment HomeFragment{51a71a9 #1 id=0x7f080102 android:switcher:2131230978:1}

Not supporting RTL applications.

if in the theme we set application to RTL <item name="android:layoutDirection">rtl</item> or something like that, the direction of moving and icon swapping is messing up.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.