Skip to content

Commit

Permalink
banner demo
Browse files Browse the repository at this point in the history
  • Loading branch information
LinweiJ committed Feb 7, 2018
1 parent 95e6fdd commit d4673f6
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# BannerView
FrameLayout+ViewPager+FragmentViewPager,a real infinite circle banner,also support simple banner.support custom scroll time,
7 changes: 7 additions & 0 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation project(':bannerview')
implementation('com.github.bumptech.glide:glide:4.4.0') {
exclude group: 'com.android.support'
}
annotationProcessor("com.github.bumptech.glide:compiler:4.4.0") {
exclude group: 'com.android.support'
}
implementation 'com.android.support:support-v4:26.1.0'
}
2 changes: 1 addition & 1 deletion demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lwj.widget.bannerview_demo">

<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,79 @@
package com.lwj.widget.bannerview_demo;

import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.lwj.widget.bannerview.BannerInterpolator;
import com.lwj.widget.bannerview.BannerPictureLoader;
import com.lwj.widget.bannerview.BannerView;
import com.lwj.widget.bannerview.OnBannerPageSelectedListener;
import com.lwj.widget.bannerview.OnBannerPictureClickListener;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

private TextView mTv_hint;
private BannerView mBannerView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ArrayList<String> mUrlList = new ArrayList<>();
mUrlList.add("http://t2.hddhhn.com/uploads/tu/201301/149/2.jpg");
mUrlList.add("http://t2.hddhhn.com/uploads/tu/201301/149/4.jpg");
mUrlList.add("http://img1.imgtn.bdimg.com/it/u=963551012,3660149984&fm=214&gp=0.jpg");
mUrlList.add("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=6959877,824205428&fm=27&gp=0.jpg");
mUrlList.add("http://t2.hddhhn.com/uploads/tu/201409/036/1.jpg");

mTv_hint = (TextView) findViewById(R.id.tv_hint);
mBannerView = (BannerView) findViewById(R.id.BannerView);
mBannerView.setFragmentManager(getSupportFragmentManager());
mBannerView.setPictureUrl(mUrlList);
mBannerView.setCircle(true);
mBannerView.setDurationFavor(4.0f);
mBannerView.setInitItem(0);
mBannerView.setInterpolatorType(BannerInterpolator.ACCELERATE_DECELERATE);
mBannerView.setPictureLoader(new BannerPictureLoader() {
@Override
public void showPicture(Fragment fragment, ImageView pictureView, String pictureUrl) {
Glide.with(fragment)
.load(pictureUrl)
.into(pictureView);
}
});
mBannerView.setPictureClickListener(new OnBannerPictureClickListener() {
@Override
public void onPictureClick(Fragment fragment, int position, List<String> pictureUrl) {
Toast.makeText(MainActivity.this,"position:"+position+"pictureUrl"+pictureUrl.get(position),Toast.LENGTH_SHORT).show();
}
});
mBannerView.setOnBannerPageSelectedListener(new OnBannerPageSelectedListener() {
@Override
public void onPageSelected(int position, String url) {
mTv_hint.setText("position"+position);
}
});
mBannerView.start();
}

@Override
protected void onStart() {
super.onStart();
mBannerView.startAutoPlay();
}

@Override
protected void onStop() {
super.onStop();
mBannerView.stopAutoPlay();
}
}
29 changes: 21 additions & 8 deletions demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@
android:layout_height="match_parent"
tools:context="com.lwj.widget.bannerview_demo.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.lwj.widget.bannerview.BannerView
android:id="@+id/BannerView"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_weight="1"
android:background="#cdcdcd"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/tv_hint"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="bottom"
android:gravity="center"
android:textColor="#ededed"
android:background="#20000000"
android:text="index" />

</com.lwj.widget.bannerview.BannerView>

</android.support.constraint.ConstraintLayout>
Binary file added screen_shot/BannerView.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d4673f6

Please sign in to comment.