0
В настоящее время я использую FAB и следую за this для раздвижных вкладок. Я хочу, чтобы анимация возрастала, когда я переключаю вкладки. БлагодаряАнимация FAB при переключении вкладок
аним/simple_grow.xml
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:toXScale="1.0"
android:toYScale="1.0"
android:duration="700"
android:pivotX="50%"
android:pivotY="50%"
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
</scale>
EDIT: ViewPagerAdapter.java
package adapter;
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
CharSequence Titles[]; // This will Store the Titles of the Tabs which are Going to be passed when ViewPagerAdapter is created
int NumbOfTabs; // Store the number of tabs, this will also be passed when the ViewPagerAdapter is created
// Build a Constructor and assign the passed Values to appropriate values in the class
public ViewPagerAdapter(FragmentManager fm,CharSequence mTitles[], int mNumbOfTabsumb) {
super(fm);
this.Titles = mTitles;
this.NumbOfTabs = mNumbOfTabsumb;
}
//This method return the fragment for the every position in the View Pager
@Override
public Fragment getItem(int position) {
if(position == 0) // if the position is 0 we are returning the First tab
{
FactorialTab factorialTab = new FactorialTab();
return factorialTab;
} else if(position == 1) // As we are having 2 tabs if the position is now 0 it must be 1 so we are returning second tab
{
PermutationTab permutationTab = new PermutationTab();
return permutationTab;
}
else {
RandomTab randomTab = new RandomTab();
return randomTab;
}
}
// This method return the titles for the Tabs in the Tab Strip
@Override
public CharSequence getPageTitle(int position) {
return Titles[position];
}
// This method return the Number of tabs for the tabs Strip
@Override
public int getCount() {
return NumbOfTabs;
}
}
MainActivity.java
package activity;
public class MainActivity extends AppCompatActivity {
Toolbar mToolbar;
ViewPager pager;
ViewPagerAdapter adapter;
SlidingTabLayout tabs;
CharSequence Titles[] = {"Factorial", "Permutation", "Random"};
int Numboftabs = 3;
FloatingActionButton fab;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
adapter = new ViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs);
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter);
tabs = (SlidingTabLayout) findViewById(R.id.tabs);
tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width
tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.fab_pressed);
}
});
tabs.setViewPager(pager);
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.show(false);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow);
fab.startAnimation(animation);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Я хотел бы знать, как узнать свое положение из ViewPagerAdapter. Спасибо: D
Вы хотите, чтобы я добавил свой код? –
Да, пожалуйста - было бы полезно – mstrengis
добавлен код: D –