Skip to content

Commit 613a895

Browse files
committed
swipe views with tabs
swipe views tabs
1 parent 040a81a commit 613a895

File tree

10 files changed

+247
-0
lines changed

10 files changed

+247
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apply plugin: 'com.android.application'
2+
3+
apply plugin: 'kotlin-android'
4+
5+
apply plugin: 'kotlin-android-extensions'
6+
7+
android {
8+
compileSdkVersion 27
9+
defaultConfig {
10+
applicationId "com.hmkcode"
11+
minSdkVersion 19
12+
targetSdkVersion 27
13+
versionCode 1
14+
versionName "1.0"
15+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16+
}
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
}
24+
25+
dependencies {
26+
implementation fileTree(dir: 'libs', include: ['*.jar'])
27+
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
28+
implementation 'com.android.support:appcompat-v7:27.1.1'
29+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
30+
implementation 'com.android.support:design:27.1.1'
31+
testImplementation 'junit:junit:4.12'
32+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
33+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
34+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.hmkcode">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.hmkcode;
2+
3+
import android.support.design.widget.TabLayout;
4+
import android.support.v4.app.FragmentActivity;
5+
import android.support.v4.view.ViewPager;
6+
import android.os.Bundle;
7+
import com.hmkcode.adapters.MyFragmentPagerAdapter;
8+
9+
public class MainActivity extends FragmentActivity {
10+
11+
MyFragmentPagerAdapter myFragmentPagerAdapter;
12+
ViewPager viewPager;
13+
TabLayout tabLayout;
14+
15+
@Override
16+
protected void onCreate(Bundle savedInstanceState) {
17+
super.onCreate(savedInstanceState);
18+
setContentView(R.layout.activity_main);
19+
20+
viewPager = (ViewPager) findViewById(R.id.viewPager);
21+
22+
setPagerAdapter();
23+
setTabLayout();
24+
}
25+
26+
private void setPagerAdapter(){
27+
myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
28+
viewPager.setAdapter(myFragmentPagerAdapter);
29+
}
30+
31+
private void setTabLayout() {
32+
tabLayout.setupWithViewPager(viewPager);
33+
34+
tabLayout.getTabAt(0).setText("First");
35+
tabLayout.getTabAt(1).setText("Second");
36+
}
37+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.hmkcode.adapters;
2+
3+
import android.support.v4.app.Fragment;
4+
import android.support.v4.app.FragmentManager;
5+
import android.support.v4.app.FragmentPagerAdapter;
6+
import com.hmkcode.fragments.FirstFragment;
7+
import com.hmkcode.fragments.SecondFragment;
8+
9+
public class MyFragmentPagerAdapter extends FragmentPagerAdapter {
10+
11+
12+
public MyFragmentPagerAdapter(FragmentManager fm) {
13+
super(fm);
14+
}
15+
16+
@Override
17+
public Fragment getItem(int position) {
18+
switch (position) {
19+
case 0:
20+
return new FirstFragment();
21+
case 1:
22+
return new SecondFragment();
23+
default:
24+
return null;
25+
}
26+
}
27+
28+
@Override
29+
public int getCount() {
30+
return 2;
31+
}
32+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.hmkcode.fragments;
2+
3+
import android.os.Bundle;
4+
import android.support.v4.app.Fragment;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import com.hmkcode.R;
9+
10+
public class FirstFragment extends Fragment {
11+
12+
public FirstFragment() {}
13+
14+
@Override
15+
public void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
}
18+
19+
@Override
20+
public View onCreateView(LayoutInflater inflater,
21+
ViewGroup container,
22+
Bundle savedInstanceState) {
23+
return inflater.inflate(R.layout.fragment_first, container, false);
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.hmkcode.fragments;
2+
3+
import android.os.Bundle;
4+
import android.support.v4.app.Fragment;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import com.hmkcode.R;
9+
10+
public class SecondFragment extends Fragment {
11+
12+
public SecondFragment() {}
13+
14+
@Override
15+
public void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
}
18+
19+
@Override
20+
public View onCreateView(LayoutInflater inflater,
21+
ViewGroup container,
22+
Bundle savedInstanceState) {
23+
return inflater.inflate(R.layout.fragment_second, container, false);
24+
}
25+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context=".MainActivity">
8+
9+
<android.support.v4.view.ViewPager
10+
xmlns:android="http://schemas.android.com/apk/res/android"
11+
android:id="@+id/viewPager"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent" />
14+
15+
<android.support.design.widget.TabLayout
16+
android:id="@+id/tabLayout"
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content" />
19+
20+
</android.support.constraint.ConstraintLayout>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
7+
<TextView
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent"
10+
android:text="First Fragment"
11+
android:gravity="center"/>
12+
13+
</android.support.constraint.ConstraintLayout>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
7+
<TextView
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent"
10+
android:text="Second Fragment"
11+
android:gravity="center"/>
12+
13+
</android.support.constraint.ConstraintLayout>

android-swipe-views-tabs/build.gradle

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
buildscript {
4+
ext.kotlin_version = '1.2.61'
5+
repositories {
6+
google()
7+
jcenter()
8+
}
9+
dependencies {
10+
classpath 'com.android.tools.build:gradle:3.1.4'
11+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12+
13+
// NOTE: Do not place your application dependencies here; they belong
14+
// in the individual module build.gradle files
15+
}
16+
}
17+
18+
allprojects {
19+
repositories {
20+
google()
21+
jcenter()
22+
}
23+
}
24+
25+
task clean(type: Delete) {
26+
delete rootProject.buildDir
27+
}

0 commit comments

Comments
 (0)