-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
shucc
committed
May 3, 2017
1 parent
93f9707
commit e1a2eb1
Showing
12 changed files
with
218 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.cchao.sample; | ||
|
||
import android.content.Context; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.Toast; | ||
|
||
import com.bumptech.glide.Glide; | ||
|
||
import org.cchao.carousel.CarouselView; | ||
import org.cchao.carousel.listener.ImageloaderListener; | ||
import org.cchao.carousel.listener.OnItemClickListener; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by shucc on 17/5/3. | ||
* cc@cchao.org | ||
*/ | ||
public class ViewPagerFragment extends Fragment { | ||
|
||
private final String TAG = getClass().getName(); | ||
|
||
private CarouselView carouselView; | ||
|
||
private List<String> imageUrls; | ||
|
||
private List<String> titles; | ||
|
||
public static ViewPagerFragment newInstance() { | ||
Bundle args = new Bundle(); | ||
ViewPagerFragment fragment = new ViewPagerFragment(); | ||
fragment.setArguments(args); | ||
return fragment; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
View rootView = inflater.inflate(R.layout.fragment_viewpager, container, false); | ||
carouselView = (CarouselView) rootView.findViewById(R.id.carouselView); | ||
initData(); | ||
return rootView; | ||
} | ||
|
||
private void initData() { | ||
carouselView.setOnItemClickListener(new OnItemClickListener() { | ||
@Override | ||
public void onClick(View view, int position) { | ||
Toast.makeText(getActivity(), "hehe" + position, Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
imageUrls = new ArrayList<>(); | ||
titles = new ArrayList<>(); | ||
imageUrls.add("http://img0.imgtn.bdimg.com/it/u=2334645085,3449212359&fm=23&gp=0.jpg"); | ||
imageUrls.add("http://pic18.nipic.com/20120115/4999414_151322555150_2.jpg"); | ||
imageUrls.add("http://att.bbs.duowan.com/forum/201204/30/201115l6j65f42kjuljluf.jpg"); | ||
imageUrls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1492060262991&di=4c3e773b8229057c53b1c36bf16d54c4&imgtype=0&src=http%3A%2F%2Fpic30.nipic.com%2F20130621%2F11295670_223619063339_2.jpg"); | ||
titles.add("我是标题一"); | ||
titles.add("我是标题二"); | ||
titles.add("我是标题三"); | ||
titles.add("我是标题四"); | ||
carouselView.with(this) | ||
.setImageUrls(imageUrls) | ||
.setTitles(titles) | ||
.setDealyTime(4 * 1000) | ||
.setShowIndicator(true) | ||
.setShowTitle(true) | ||
.setAutoSwitch(false) | ||
.setCanLoop(false) | ||
.setInterceptParent(false) | ||
.setImageLoaderListener(new ImageloaderListener() { | ||
@Override | ||
public void loadImage(Context context, ImageView imageView, int position) { | ||
Glide.with(context) | ||
.load(imageUrls.get(position)) | ||
.into(imageView); | ||
} | ||
}) | ||
.start(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/org/cchao/sample/ViewPagerTestActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.cchao.sample; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentPagerAdapter; | ||
import android.support.v4.view.ViewPager; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by shucc on 17/5/2. | ||
* cc@cchao.org | ||
*/ | ||
public class ViewPagerTestActivity extends AppCompatActivity { | ||
|
||
private ViewPager viewPager; | ||
|
||
private List<Fragment> fragments; | ||
|
||
public static void launch(Context context) { | ||
Intent starter = new Intent(context, ViewPagerTestActivity.class); | ||
context.startActivity(starter); | ||
} | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_viewpager); | ||
|
||
viewPager = (ViewPager) findViewById(R.id.viewPager); | ||
|
||
fragments = new ArrayList<>(); | ||
fragments.add(ViewPagerFragment.newInstance()); | ||
fragments.add(ViewPagerFragment.newInstance()); | ||
fragments.add(ViewPagerFragment.newInstance()); | ||
|
||
viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) { | ||
@Override | ||
public Fragment getItem(int position) { | ||
return fragments.get(position); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return 3; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?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"> | ||
|
||
<android.support.v4.view.ViewPager | ||
android:id="@+id/viewPager" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<org.cchao.carousel.CarouselView | ||
android:id="@+id/carouselView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:carousel_indicator_drawable_selected="@drawable/ic_indicator_selected" | ||
app:carousel_indicator_drawable_unselected="@drawable/ic_indicator_unselected" | ||
app:carousel_indicator_width="24dp" | ||
app:carousel_indicator_height="2dp" | ||
app:carousel_indicator_padding="8dp" | ||
app:carousel_indicator_margin_bottom="8dp" | ||
app:carousel_title_margin_bottom="18dp"/> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters