-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liang02.wang
committed
Jan 8, 2020
1 parent
c17ae00
commit 3a7e13b
Showing
12 changed files
with
210 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package viewpager; | ||
|
||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import me.liam.fragmentation.R; | ||
import me.liam.support.SupportFragment; | ||
|
||
/** | ||
* Create on 2020/1/8. | ||
*/ | ||
public class ItemPageFragment extends SupportFragment { | ||
|
||
public static ItemPageFragment newInstance(int count) { | ||
|
||
Bundle args = new Bundle(); | ||
args.putInt("count",count); | ||
ItemPageFragment fragment = new ItemPageFragment(); | ||
fragment.setArguments(args); | ||
return fragment; | ||
} | ||
|
||
private View rootView; | ||
private TextView textView; | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
rootView = View.inflate(getContext(), R.layout.fragment_item_page,null); | ||
textView = rootView.findViewById(R.id.tv); | ||
textView.setText(""+getArguments().getInt("count")); | ||
Log.e("ItemPageFragment",getArguments().getInt("count") + "onCreateView"); | ||
return rootView; | ||
} | ||
|
||
@Override | ||
public void onLazyInit(Bundle savedInstanceState) { | ||
super.onLazyInit(savedInstanceState); | ||
Log.e("ItemPageFragment",getArguments().getInt("count") + "onLazyInit"); | ||
} | ||
|
||
@Override | ||
public void setUserVisibleHint(boolean isVisibleToUser) { | ||
super.setUserVisibleHint(isVisibleToUser); | ||
Log.e("ItemPageFragment",getArguments().getInt("count") + "setUserVisibleHint" + isVisibleToUser); | ||
} | ||
|
||
@Override | ||
public void onStart() { | ||
super.onStart(); | ||
Log.e("ItemPageFragment",getArguments().getInt("count") + "onStart"); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
Log.e("ItemPageFragment",getArguments().getInt("count") + "onResume"); | ||
} | ||
} |
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,22 @@ | ||
package viewpager; | ||
|
||
import android.os.Bundle; | ||
|
||
import androidx.annotation.Nullable; | ||
import me.liam.fragmentation.R; | ||
import me.liam.support.SupportActivity; | ||
|
||
/** | ||
* Create on 2020/1/8. | ||
*/ | ||
public class ViewPagerActivity extends SupportActivity { | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_vp_root); | ||
if (findFragmentByClass(ViewPagerFragment.class) == null){ | ||
loadRootFragment(R.id.container,ViewPagerFragment.newInstance()); | ||
} | ||
} | ||
} |
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,71 @@ | ||
package viewpager; | ||
|
||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.google.android.material.tabs.TabLayout; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.fragment.app.Fragment; | ||
import androidx.fragment.app.FragmentManager; | ||
import androidx.fragment.app.FragmentPagerAdapter; | ||
import androidx.viewpager.widget.ViewPager; | ||
import me.liam.fragmentation.R; | ||
import me.liam.support.SupportFragment; | ||
|
||
/** | ||
* Create on 2020/1/8. | ||
*/ | ||
public class ViewPagerFragment extends SupportFragment { | ||
|
||
public static ViewPagerFragment newInstance() { | ||
|
||
Bundle args = new Bundle(); | ||
|
||
ViewPagerFragment fragment = new ViewPagerFragment(); | ||
fragment.setArguments(args); | ||
return fragment; | ||
} | ||
|
||
private View rootView; | ||
private TabLayout tabLayout; | ||
private ViewPager viewPager; | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
rootView = View.inflate(getContext(), R.layout.fragment_vp_root,null); | ||
tabLayout = rootView.findViewById(R.id.tabLayout); | ||
viewPager = rootView.findViewById(R.id.viewPager); | ||
tabLayout.addTab(tabLayout.newTab().setText("1")); | ||
tabLayout.addTab(tabLayout.newTab().setText("2")); | ||
tabLayout.addTab(tabLayout.newTab().setText("3")); | ||
tabLayout.addTab(tabLayout.newTab().setText("4")); | ||
tabLayout.addTab(tabLayout.newTab().setText("5")); | ||
PagerAdapter adapter = new PagerAdapter(getChildFragmentManager(),FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); | ||
viewPager.setAdapter(adapter); | ||
tabLayout.setupWithViewPager(viewPager); | ||
return rootView; | ||
} | ||
|
||
static class PagerAdapter extends FragmentPagerAdapter { | ||
|
||
public PagerAdapter(@NonNull FragmentManager fm, int behavior) { | ||
super(fm, behavior); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Fragment getItem(int position) { | ||
return ItemPageFragment.newInstance(position); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return 5; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<FrameLayout | ||
android:id="@+id/container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"/> | ||
</LinearLayout> |
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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<TextView | ||
android:id="@+id/tv" | ||
android:gravity="center" | ||
android:textSize="50dp" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
</LinearLayout> |
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,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<com.google.android.material.tabs.TabLayout | ||
android:id="@+id/tabLayout" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"/> | ||
<androidx.viewpager.widget.ViewPager | ||
android:id="@+id/viewPager" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"></androidx.viewpager.widget.ViewPager> | ||
</LinearLayout> |