-
-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update sample.
- Loading branch information
Showing
39 changed files
with
1,124 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 66 additions & 18 deletions
84
app/src/main/java/com/example/zhpan/circleviewpager/activity/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,91 @@ | ||
package com.example.zhpan.circleviewpager.activity; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.viewpager.widget.ViewPager; | ||
|
||
import android.view.View; | ||
import android.widget.RadioGroup; | ||
|
||
import com.example.zhpan.circleviewpager.R; | ||
import com.example.zhpan.circleviewpager.adapter.AdapterFragmentPager; | ||
|
||
import butterknife.BindView; | ||
import butterknife.ButterKnife; | ||
|
||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
@BindView(R.id.rg_tab) | ||
RadioGroup rgTab; | ||
@BindView(R.id.vp_fragment) | ||
ViewPager mViewPager; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
ButterKnife.bind(this); | ||
initData(); | ||
setListener(); | ||
} | ||
|
||
public void onClick(View view) { | ||
Intent intent; | ||
switch (view.getId()) { | ||
case R.id.tv_page_style: | ||
intent = new Intent(this, PageStyleActivity.class); | ||
break; | ||
case R.id.btn_view_pager3: | ||
intent = new Intent(this, PhotoViewActivity.class); | ||
break; | ||
case R.id.btn_view_pager5: | ||
intent = new Intent(this, PageTransformerActivity.class); | ||
private void initData() { | ||
AdapterFragmentPager mAdapter = new AdapterFragmentPager(getSupportFragmentManager()); | ||
mViewPager.setAdapter(mAdapter); | ||
mViewPager.setOffscreenPageLimit(2); | ||
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { | ||
@Override | ||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { | ||
|
||
} | ||
|
||
@Override | ||
public void onPageSelected(int position) { | ||
rgTab.check(getCheckedId(position)); | ||
} | ||
|
||
@Override | ||
public void onPageScrollStateChanged(int state) { | ||
|
||
} | ||
}); | ||
} | ||
|
||
private int getCheckedId(int position) { | ||
int checkedId = R.id.rb_home; | ||
switch (position) { | ||
case 0: | ||
checkedId = R.id.rb_home; | ||
break; | ||
case R.id.btn_indicator_style: | ||
intent = new Intent(this, IndicatorStyleActivity.class); | ||
case 1: | ||
checkedId = R.id.rb_find; | ||
break; | ||
case R.id.btn_view_pager4: | ||
default: | ||
intent = new Intent(this, NetworkBannerActivity.class); | ||
case 2: | ||
checkedId = R.id.rb_add; | ||
break; | ||
} | ||
startActivity(intent); | ||
return checkedId; | ||
} | ||
|
||
private void setListener() { | ||
rgTab.setOnCheckedChangeListener((group, checkedId) -> { | ||
if (checkedId == R.id.rb_home) { | ||
mViewPager.setCurrentItem(AdapterFragmentPager.PAGE_HOME, false); | ||
|
||
} else if (checkedId == R.id.rb_find) { | ||
mViewPager.setCurrentItem(AdapterFragmentPager.PAGE_FIND, false); | ||
|
||
} else if (checkedId == R.id.rb_add) { | ||
mViewPager.setCurrentItem(AdapterFragmentPager.PAGE_OTHERS, false); | ||
} | ||
}); | ||
} | ||
|
||
public static void start(Context context) { | ||
context.startActivity(new Intent(context, MainActivity.class)); | ||
} | ||
|
||
} |
78 changes: 0 additions & 78 deletions
78
app/src/main/java/com/example/zhpan/circleviewpager/activity/PageTransformerActivity.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
app/src/main/java/com/example/zhpan/circleviewpager/adapter/AdapterFragmentPager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.example.zhpan.circleviewpager.adapter; | ||
|
||
import android.util.SparseArray; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.fragment.app.Fragment; | ||
import androidx.fragment.app.FragmentManager; | ||
import androidx.fragment.app.FragmentPagerAdapter; | ||
|
||
|
||
import com.example.zhpan.circleviewpager.fragment.BaseFragment; | ||
import com.example.zhpan.circleviewpager.fragment.FindFragment; | ||
import com.example.zhpan.circleviewpager.fragment.HomeFragment; | ||
import com.example.zhpan.circleviewpager.fragment.OthersFragment; | ||
|
||
import java.util.List; | ||
|
||
public class AdapterFragmentPager extends FragmentPagerAdapter { | ||
|
||
public static final int PAGE_HOME = 0; | ||
|
||
public static final int PAGE_FIND = 1; | ||
|
||
public static final int PAGE_OTHERS = 2; | ||
|
||
private SparseArray<BaseFragment> fragmentList; | ||
|
||
public AdapterFragmentPager(FragmentManager fm) { | ||
super(fm); | ||
fragmentList = getFragments(); | ||
} | ||
|
||
private SparseArray<BaseFragment> getFragments() { | ||
SparseArray<BaseFragment> fragmentList = new SparseArray<>(); | ||
fragmentList.put(PAGE_HOME, HomeFragment.getInstance()); | ||
fragmentList.put(PAGE_FIND, FindFragment.getInstance()); | ||
fragmentList.put(PAGE_OTHERS, OthersFragment.getInstance()); | ||
return fragmentList; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Object instantiateItem(@NonNull ViewGroup container, int position) { | ||
Fragment fragment = (Fragment) super.instantiateItem(container, position); | ||
fragmentList.put(position, (BaseFragment) fragment); | ||
return fragment; | ||
} | ||
|
||
@Override | ||
public Fragment getItem(int position) { | ||
return fragmentList.get(position); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
if (fragmentList != null) { | ||
return fragmentList.size(); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.