Skip to content

Commit 2f501fd

Browse files
author
Sira Lam
committed
Updated README for v1.0.5
1 parent 0eabede commit 2f501fd

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

README.md

+34-23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A ViewPager and a PagerAdapter that can:
44

55
1. AutoScroll (On/Off able)
66
2. Infinite Loop (On/Off able)
7-
3. ViewPager's height can be wrap_content
7+
3. ViewPager's height can be wrap_content / an aspect ratio
88
4. Adjustable auto scroll interval
99
5. Won't scroll nor loop if there is only 1 item
1010
6. Works well with notifyDataSetChanged()
@@ -27,7 +27,7 @@ I cannot find one that fits all of the below requirements:
2727
2. Last updated in less than 3 years
2828
3. Good infinite looping effect
2929
4. Configurable auto-scroll
30-
5. ViewPager that supports wrap_content (or at least aspect ratio)
30+
5. ViewPager that supports fixed aspect ratio (Or wrap_content)
3131
6. Good support with Page Indicators
3232

3333
Especially for 6, even some of them supports, they provide built-in indicators only; or does not tell user how to implement their own indicator.
@@ -50,7 +50,7 @@ allprojects {
5050
And then add the below to your app's build.gradle:
5151

5252
```groovy
53-
implementation 'com.asksira.android:loopingviewpager:1.0.4'
53+
implementation 'com.asksira.android:loopingviewpager:1.0.5'
5454
```
5555

5656
### Step 1: Create LoopingViewPager in XML
@@ -63,15 +63,22 @@ And then add the below to your app's build.gradle:
6363
app:isInfinite="true"
6464
app:autoScroll="true"
6565
app:scrollInterval="5000"
66-
app:wrap_content="true"/>
66+
app:viewpagerAspectRatio="1.33"/>
6767
```
6868

69-
| Attribute Name | Default | Allowed Values |
70-
|:-----------------|:--------|:------------------------------|
71-
| isInfinite | false | true / false |
72-
| autoScroll | false | true / false |
73-
| wrap_content | true | true / false |
74-
| scrollInterval | 5000 | any integer (represents ms) |
69+
| Attribute Name | Default | Allowed Values |
70+
|:------------------------|:--------|:------------------------------|
71+
| isInfinite | false | true / false |
72+
| autoScroll | false | true / false |
73+
| viewpagerAspectRatio | 0 | any float (width / height) |
74+
| wrap_content | true | true / false |
75+
| scrollInterval | 5000 | any integer (represents ms) |
76+
77+
viewpagerAspectRatio 0 means does not apply aspectRatio.
78+
That means, default LoopingViewPager has no aspect ratio and wrap_content is true.
79+
Once aspect ratio is set, wrap_content will be overrided (meaningless).
80+
81+
In most cases, you should set an aspect ratio.
7582

7683
If you wonder why you need to set `app:wrap_content="true"`, take a look at [this Stackoverflow post](https://stackoverflow.com/questions/8394681/android-i-am-unable-to-have-viewpager-wrap-content).
7784

@@ -80,7 +87,7 @@ If you wonder why you need to set `app:wrap_content="true"`, take a look at [thi
8087
You should
8188
1. Specify the data type in the generic (`<DataType>`)
8289
2. Create your own constructor according to this `DataType`
83-
3. override `getItemView`
90+
3. override `inflateView()` and `bindView()`
8491

8592
```java
8693
public class DemoInfiniteAdapter extends LoopingPagerAdapter<Integer> {
@@ -89,22 +96,21 @@ public class DemoInfiniteAdapter extends LoopingPagerAdapter<Integer> {
8996
super(context, itemList, isInfinite);
9097
}
9198

92-
//You should return the View (With data binded) to display in this method.
99+
//This method will be triggered if the item View has not been inflated before.
93100
@Override
94-
protected View getItemView(View convertView, int listPosition, ViewPager container) {
95-
if (convertView == null) {
96-
convertView = LayoutInflater.from(context).inflate(R.layout.item_pager, null);
97-
container.addView(convertView);
98-
}
99-
100-
//Bind your view elements with data in itemList here.
101-
//You can also consider using a ViewHolder pattern.
102-
//Below is just an example in the demo app.
101+
protected View inflateView() {
102+
return LayoutInflater.from(context).inflate(R.layout.item_pager, null);
103+
}
104+
105+
//Bind your data with your item View here.
106+
//Below is just an example in the demo app.
107+
//You can assume convertView will not be null here.
108+
//You may also consider using a ViewHolder pattern.
109+
@Override
110+
protected void bindView(View convertView, int listPosition) {
103111
convertView.findViewById(R.id.image).setBackgroundColor(context.getResources().getColor(getBackgroundColor(listPosition)));
104112
TextView description = convertView.findViewById(R.id.description);
105113
description.setText(String.valueOf(itemList.get(listPosition)));
106-
107-
return convertView;
108114
}
109115
}
110116
```
@@ -234,6 +240,11 @@ if you cannot accept these minor defects, I suggest you use `onIndicatorPageChan
234240

235241
## Release notes
236242

243+
v1.0.5
244+
- Added asepct ratio attribute for `LoopingViewPager`
245+
- Rewrote the way of caching Views in `LoopingPagerAdapter`, and therefore separated inflation and data binding
246+
- Rewrote the way of implementing ViewPager wrap_content
247+
237248
v1.0.4
238249
- Indicator now works with page skipping as well (By calling `selectCurrentItem()`)
239250
- Leviated indicator fluctuating phenomenon when using `onIndicatorProgress()` callback

0 commit comments

Comments
 (0)