Skip to content

Commit

Permalink
更新有朋友让加入是否拦截事件的判断
Browse files Browse the repository at this point in the history
Change-Id: Ib74f7dd763de425f6f8491394e9247e83c12a34a
  • Loading branch information
youth5201314 committed May 25, 2020
1 parent 17d68f8 commit b369212
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
Gradle
```groovy
dependencies{
compile 'com.youth.banner:banner:2.0.9'
compile 'com.youth.banner:banner:2.0.10'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

import android.os.Bundle;

import com.google.android.material.tabs.TabLayout;
import com.test.banner.R;
import com.test.banner.adapter.ImageAdapter;
import com.test.banner.bean.DataBean;
import com.test.banner.util.TabLayoutMediator;
import com.youth.banner.Banner;
import com.youth.banner.indicator.CircleIndicator;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

import com.google.android.material.tabs.TabLayout;
import com.test.banner.R;
import com.test.banner.util.TabLayoutMediator;

import butterknife.BindView;
import butterknife.ButterKnife;

Expand All @@ -21,6 +24,8 @@ public class Vp2FragmentRecyclerviewActivity extends AppCompatActivity {
ViewPager2 viewPager2;
@BindView(R.id.tab_layout)
TabLayout mTabLayout;
@BindView(R.id.banner)
Banner mBanner;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -32,11 +37,11 @@ protected void onCreate(Bundle savedInstanceState) {
@NonNull
@Override
public Fragment createFragment(int position) {
if (position==0) {
if (position == 0) {
return BannerListFragment.newInstance(position);
}else if (position==1){
} else if (position == 1) {
return BlankFragment.newInstance();
}else{
} else {
return BannerFragment.newInstance();
}
}
Expand All @@ -47,8 +52,14 @@ public int getItemCount() {
}
});

new TabLayoutMediator(mTabLayout,viewPager2,(tab, position) -> {
tab.setText("页面"+position);
new TabLayoutMediator(mTabLayout, viewPager2, (tab, position) -> {
tab.setText("页面" + position);
}).attach();


mBanner.addBannerLifecycleObserver(this)
.setAdapter(new ImageAdapter(DataBean.getTestData()))
.setIntercept(false)
.setIndicator(new CircleIndicator(this));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
android:layout_height="180dp"
android:orientation="vertical">

<ImageView
android:id="@+id/discover_img"
<com.youth.banner.Banner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="180dp"
android:scaleType="fitXY"
android:src="@drawable/image7" />
android:layout_height="180dp"/>

</LinearLayout>

Expand Down
Binary file modified app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<resources>
<string name="app_name">Banner Example</string>
<string name="situationOne">ScrollView嵌套banner</string>
<string name="app_name">Banner</string>

</resources>
4 changes: 2 additions & 2 deletions banner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "2.0.9"
version = "2.0.10"

android {
compileSdkVersion 29

defaultConfig {
minSdkVersion 14
targetSdkVersion 29
versionCode 200009
versionCode 200010
versionName version
consumerProguardFiles 'proguard-rules.pro'
}
Expand Down
9 changes: 8 additions & 1 deletion banner/src/main/java/com/youth/banner/Banner.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public class Banner<T, BA extends BannerAdapter> extends FrameLayout implements
private float mStartX, mStartY;
// 记录viewpager2是否被拖动
private boolean mIsViewPager2Drag;
// 是否要拦截事件
private boolean isIntercept = true;

@Retention(SOURCE)
@IntDef( {HORIZONTAL, VERTICAL})
Expand Down Expand Up @@ -211,7 +213,7 @@ public boolean dispatchTouchEvent(MotionEvent ev) {

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (!getViewPager2().isUserInputEnabled()) {
if (!getViewPager2().isUserInputEnabled() || !isIntercept) {
return super.onInterceptTouchEvent(event);
}
switch (event.getAction()) {
Expand Down Expand Up @@ -446,6 +448,11 @@ public int getRealCount() {
//-----------------------------------------------------------------------------------------


public Banner setIntercept(boolean intercept) {
isIntercept = intercept;
return this;
}

public Banner setCurrentItem(int position) {
return setCurrentItem(position, true);
}
Expand Down

0 comments on commit b369212

Please sign in to comment.