Skip to content

Commit

Permalink
支持ViewPager
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Jul 16, 2019
1 parent 699f95d commit 1cdc850
Show file tree
Hide file tree
Showing 10 changed files with 401 additions and 19 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<activity
android:name=".activity.TestWeekActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />
<activity
android:name=".activity.TestViewPagerActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />


</application>
Expand Down
14 changes: 10 additions & 4 deletions app/src/main/java/com/necer/ncalendar/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void week_unSelected(View view) {
}

public void week_multiple(View view) {
startActivity(getNewIntent(TestWeekActivity.class, SelectedModel.MULTIPLE, "周日历多选"));
startActivity(getNewIntent(TestWeekActivity.class, SelectedModel.MULTIPLE, "周日历多选"));
}

public void miui9_selected(View view) {
Expand All @@ -56,7 +56,7 @@ public void miui9_unSelected(View view) {
}

public void miui9_multiple(View view) {
startActivity(getNewIntent(TestMiui9Activity.class, SelectedModel.MULTIPLE, "miui9多选"));
startActivity(getNewIntent(TestMiui9Activity.class, SelectedModel.MULTIPLE, "miui9多选"));
}

public void miui10_selected(View view) {
Expand All @@ -68,7 +68,7 @@ public void miui10_unSelected(View view) {
}

public void miui10_multiple(View view) {
startActivity(getNewIntent(TestMiui10Activity.class, SelectedModel.MULTIPLE, "miui10多选"));
startActivity(getNewIntent(TestMiui10Activity.class, SelectedModel.MULTIPLE, "miui10多选"));
}

public void emiui_selected(View view) {
Expand All @@ -80,7 +80,7 @@ public void emiui_unSelected(View view) {
}

public void emiui_multiple(View view) {
startActivity(getNewIntent(TestEmuiActivity.class, SelectedModel.MULTIPLE, "emiui多选"));
startActivity(getNewIntent(TestEmuiActivity.class, SelectedModel.MULTIPLE, "emiui多选"));
}

public void toHoldWeek(View view) {
Expand All @@ -95,6 +95,12 @@ public void custom_painter(View view) {
startActivity(new Intent(this, CustomCalendarActivity.class));
}

public void viewpager(View view) {
startActivity(new Intent(this, TestViewPagerActivity.class));
}



private Intent getNewIntent(Class<? extends BaseActivity> clazz, SelectedModel selectedModel, String title) {
Intent intent = new Intent(this, clazz);
intent.putExtra("selectedModel", selectedModel);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.necer.ncalendar.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.necer.ncalendar.R;
import com.necer.ncalendar.adapter.ViewPagerAdapter;

public class TestViewPagerActivity extends AppCompatActivity {


private ViewPager viewPager;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_pager);

viewPager = findViewById(R.id.view_pager);
viewPager.setPageMargin(100);
viewPager.setAdapter(new ViewPagerAdapter(this));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.necer.ncalendar.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.necer.ncalendar.R;

public class ViewPagerAdapter extends PagerAdapter {


private Context mContext;

public ViewPagerAdapter(Context context) {
this.mContext = context;
}


@Override
public int getCount() {
return 3;
}

@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}


@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
View view = View.inflate(mContext, R.layout.item_view_pager, null);

TextView textView = view.findViewById(R.id.tv);
textView.setText(view + "");
container.addView(view);
return view;
}

}
25 changes: 25 additions & 0 deletions app/src/main/res/layout/activity_general.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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.necer.view.WeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<com.necer.calendar.Miui10Calendar
android:layout_width="match_parent"
android:layout_height="match_parent">


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="asdfasdf"/>

</com.necer.calendar.Miui10Calendar>



</LinearLayout>
8 changes: 7 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,19 @@
android:text="日历和子view之间添加view" />



<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="custom_painter"
android:text="自定义页面(两种效果)" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="viewpager"
android:text="view_pager" />


<TextView
android:id="@+id/tv_version"
android:layout_width="wrap_content"
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/res/layout/activity_view_pager.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<com.necer.view.WeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content" />


<com.necer.calendar.Miui10Calendar
android:layout_width="match_parent"
android:layout_height="match_parent">


<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingRight="50dp"
android:paddingLeft="50dp"
android:clipToPadding="false"/>

</com.necer.calendar.Miui10Calendar>


</LinearLayout>
Loading

0 comments on commit 1cdc850

Please sign in to comment.