Step 1:
activity_taps.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_height="match_parent"> <android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorLiteGreen"> </android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" /> </LinearLayout>
Step 2:
TapViewActivity.java
public class TapViewActivity extends AppCompatActivity { TabLayout tabLayout; ViewPager viewPager; ImageView im_arrow; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_taps); tabLayout=(TabLayout)findViewById(R.id.tabLayout); viewPager=(ViewPager)findViewById(R.id.viewPager); im_arrow=(ImageView)findViewById(R.id.im_arrow); tabLayout.addTab(tabLayout.newTab().setText("Tap1")); tabLayout.addTab(tabLayout.newTab().setText("Tap2")); tabLayout.addTab(tabLayout.newTab().setText("Tap3")); tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); im_arrow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); final ViewPagerAdapter adapter = new ViewPagerAdapter(this,getSupportFragmentManager(), tabLayout.getTabCount()); viewPager.setAdapter(adapter); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Overridepublic void onTabSelected(TabLayout.Tab tab) {viewPager.setCurrentItem(tab.getPosition());
} @Overridepublic void onTabUnselected(TabLayout.Tab tab) { } @Overridepublic void onTabReselected(TabLayout.Tab tab) { } }); } }Step 3:Tap1.javapublic class Tap1 extends Fragment { LinearLayout ly1,ly2; public ApprovedTap() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.tap1, container, false);// Inflate the layout for this fragmentreturn view; }}
Step 4:Tap2.javapublic class Tap2 extends Fragment { LinearLayout ly1,ly2; public ApprovedTap() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.tap2, container, false); // Inflate the layout for this fragmentreturn view; }}Step 5:Tap3.javapublic class Tap3 extends Fragment { LinearLayout ly1,ly2; public ApprovedTap() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.tap3, container, false); // Inflate the layout for this fragmentreturn view; }}Step 6:tap1.xml<?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"> <LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="2"android:gravity="center|left"> <TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Tap 1"android:layout_marginLeft="20dp"android:textColor="@color/colorDarkGreen"android:textSize="20dp"/> </LinearLayout> </LinearLayout>Step 7:tap2.xml<?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"> <LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="2"android:gravity="center|left"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Tap 2"android:layout_marginLeft="20dp"android:textColor="@color/colorDarkGreen"android:textSize="20dp"/> </LinearLayout> </LinearLayout>Step 8:tap3.xml<?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"> <LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="2"android:gravity="center|left"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Tap 3"android:layout_marginLeft="20dp"android:textColor="@color/colorDarkGreen"android:textSize="20dp"/> </LinearLayout> </LinearLayout>
No comments:
Post a Comment