-
Notifications
You must be signed in to change notification settings - Fork 83
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
Showing
14 changed files
with
551 additions
and
4 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
127 changes: 127 additions & 0 deletions
127
app/src/main/java/com/example/zjy/zjywidget/sample/ScrollIndicatorTestActivity.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,127 @@ | ||
package com.example.zjy.zjywidget.sample; | ||
|
||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.FrameLayout; | ||
|
||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.ActionBar; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.viewpager.widget.PagerAdapter; | ||
import androidx.viewpager.widget.ViewPager; | ||
|
||
import com.example.zjy.zjywidget.R; | ||
import com.zjywidget.widget.indicator.YStickIndicator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ScrollIndicatorTestActivity extends AppCompatActivity { | ||
|
||
private ViewPager viewPager; | ||
private YStickIndicator indicator; | ||
private Button addBtn; | ||
List<Integer> itemList = new ArrayList<>(); | ||
MyPageAdapter pageAdapter; | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_scroll_indicator); | ||
|
||
ActionBar actionBar = getSupportActionBar(); | ||
if (actionBar != null) { | ||
actionBar.setTitle("YStickIndicator"); | ||
} | ||
|
||
viewPager = findViewById(R.id.view_pager); | ||
indicator = findViewById(R.id.indicator); | ||
addBtn = findViewById(R.id.add_btn); | ||
|
||
addBtn.setOnClickListener(view -> { | ||
itemList.add(Color.DKGRAY); | ||
indicator.setTotalCount(itemList.size()); | ||
viewPager.setAdapter(pageAdapter); | ||
}); | ||
|
||
itemList.add(Color.RED); | ||
itemList.add(Color.BLUE); | ||
itemList.add(Color.YELLOW); | ||
itemList.add(Color.GREEN); | ||
itemList.add(Color.LTGRAY); | ||
itemList.add(Color.MAGENTA); | ||
itemList.add(Color.BLACK); | ||
itemList.add(Color.CYAN); | ||
pageAdapter = new MyPageAdapter(itemList); | ||
viewPager.setAdapter(pageAdapter); | ||
|
||
indicator.setTotalCount(itemList.size()); | ||
|
||
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { | ||
@Override | ||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { | ||
|
||
} | ||
|
||
@Override | ||
public void onPageSelected(int position) { | ||
indicator.setCurIndex(position); | ||
} | ||
|
||
@Override | ||
public void onPageScrollStateChanged(int state) { | ||
|
||
} | ||
}); | ||
|
||
} | ||
|
||
private View generateItem(int pos, int color) { | ||
View itemView = new View(this); | ||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); | ||
itemView.setLayoutParams(params); | ||
itemView.setBackgroundColor(color); | ||
|
||
itemView.setOnClickListener(view -> { | ||
itemList.remove(pos); | ||
indicator.setTotalCount(itemList.size()); | ||
viewPager.setAdapter(pageAdapter); | ||
}); | ||
return itemView; | ||
} | ||
|
||
|
||
public class MyPageAdapter extends PagerAdapter { | ||
|
||
private List<Integer> itemList = new ArrayList<>(); | ||
|
||
public MyPageAdapter(List<Integer> list) { | ||
this.itemList = list; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return itemList.size(); | ||
} | ||
|
||
@Override | ||
public boolean isViewFromObject(View view, Object object) { | ||
return view == object; | ||
} | ||
|
||
@Override | ||
public Object instantiateItem(ViewGroup container, final int position) { | ||
View itemView = generateItem(position, itemList.get(position)); | ||
container.addView(itemView); | ||
return itemView; | ||
} | ||
|
||
@Override | ||
public void destroyItem(ViewGroup container, int position, Object object) { | ||
container.removeView((View) object); | ||
} | ||
} | ||
} |
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,36 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
|
||
<androidx.viewpager.widget.ViewPager | ||
android:id="@+id/view_pager" | ||
android:layout_width="match_parent" | ||
android:layout_height="200dp" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<com.zjywidget.widget.indicator.YStickIndicator | ||
android:id="@+id/indicator" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintBottom_toBottomOf="@+id/view_pager" | ||
android:layout_marginBottom="10dp" | ||
app:stick_indicator_small_dot_width="8dp" | ||
app:stick_indicator_big_dot_width="10dp" | ||
app:stick_indicator_dot_padding="6dp"/> | ||
|
||
<Button | ||
android:id="@+id/add_btn" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="20dp" | ||
android:text="添加" | ||
android:visibility="gone" | ||
app:layout_constraintTop_toBottomOf="@+id/view_pager"/> | ||
|
||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.