-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 24 | ||
buildToolsVersion "25.0.2" | ||
defaultConfig { | ||
applicationId "com.qf.viewpagertest01" | ||
minSdkVersion 14 | ||
targetSdkVersion 24 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
compile 'com.android.support:appcompat-v7:24.2.1' | ||
testCompile 'junit:junit:4.12' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in C:\Users\Administrator\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.qf.viewpagertest01; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.qf.viewpagertest01", appContext.getPackageName()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.qf.viewpagertest01"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.qf.viewpagertest01; | ||
|
||
import android.os.Handler; | ||
import android.os.Message; | ||
import android.os.SystemClock; | ||
import android.support.v4.view.ViewPager; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.AbsListView; | ||
import android.widget.ImageView; | ||
import android.widget.LinearLayout; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private Handler handler = new Handler(){ | ||
@Override | ||
public void handleMessage(Message msg) { | ||
vp.setCurrentItem(vp.getCurrentItem()+1); | ||
handler.sendEmptyMessageDelayed(0,5000); | ||
} | ||
}; | ||
|
||
private ViewPager vp; | ||
private int[] imgs = new int[]{R.drawable.p1,R.drawable.p2,R.drawable.p3,R.drawable.p4,R.drawable.pp1,R.drawable.tangyixin}; | ||
private List<ImageView> imageViews; | ||
private LinearLayout dotLayout; | ||
private int prePosition = 0; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
dotLayout = ((LinearLayout) findViewById(R.id.dot_layou)); | ||
vp = ((ViewPager) findViewById(R.id.viewpager)); | ||
initData(); | ||
MyAdapter adapter = new MyAdapter(imageViews); | ||
vp.setAdapter(adapter); | ||
vp.setCurrentItem(6*10000); | ||
dotLayout.getChildAt(0).setEnabled(false); | ||
// handler.sendEmptyMessage(0); | ||
vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { | ||
@Override | ||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { | ||
|
||
} | ||
|
||
@Override | ||
public void onPageSelected(int position) { | ||
dotLayout.getChildAt(prePosition).setEnabled(true); | ||
dotLayout.getChildAt(position%6).setEnabled(false); | ||
prePosition = position%6; | ||
} | ||
|
||
@Override | ||
public void onPageScrollStateChanged(int state) { | ||
|
||
} | ||
}); | ||
|
||
} | ||
|
||
private void initData() { | ||
imageViews = new ArrayList<>(); | ||
for (int i = 0; i < imgs.length; i++) { | ||
ImageView imageView = new ImageView(this); | ||
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); | ||
imageView.setImageResource(imgs[i]); | ||
imageViews.add(imageView); | ||
View dotView = new View(this); | ||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(10,10); | ||
params.leftMargin = 10; | ||
dotView.setLayoutParams(params); | ||
dotView.setBackgroundResource(R.drawable.dot_background); | ||
dotLayout.addView(dotView); | ||
} | ||
|
||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.qf.viewpagertest01; | ||
|
||
import android.support.v4.view.PagerAdapter; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by Administrator on 2017/3/22 0022. | ||
*/ | ||
|
||
public class MyAdapter extends PagerAdapter { | ||
private List<ImageView> list; | ||
|
||
public MyAdapter(List<ImageView> list) { | ||
this.list = list; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return Integer.MAX_VALUE; | ||
} | ||
|
||
@Override | ||
public boolean isViewFromObject(View view, Object object) { | ||
return view==object; | ||
} | ||
|
||
@Override | ||
public Object instantiateItem(ViewGroup container, int position) { | ||
|
||
|
||
ImageView imageView = list.get(position%6); | ||
container.addView(imageView); | ||
return imageView; | ||
} | ||
|
||
@Override | ||
public void destroyItem(ViewGroup container, int position, Object object) { | ||
container.removeView(list.get(position%6)); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:state_enabled="true" android:drawable="@drawable/white_dot" /> | ||
<item android:state_enabled="false" android:drawable="@drawable/red_dot" /> | ||
</selector> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<corners android:radius="5dp" /> | ||
<solid android:color="#ff3232" /> | ||
</shape> |