本文整理汇总了Java中android.support.design.widget.SwipeDismissBehavior类的典型用法代码示例。如果您正苦于以下问题:Java SwipeDismissBehavior类的具体用法?Java SwipeDismissBehavior怎么用?Java SwipeDismissBehavior使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SwipeDismissBehavior类属于android.support.design.widget包,在下文中一共展示了SwipeDismissBehavior类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupSwipe
import android.support.design.widget.SwipeDismissBehavior; //导入依赖的package包/类
private void setupSwipe(ItemTrackedBeaconBinding beaconBinding) {
final SwipeDismissBehavior<CardView> swipe = new SwipeDismissBehavior();
swipe.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_ANY);
swipe.setListener(new SwipeDismissBehavior.OnDismissListener() {
@Override
public void onDismiss(View view) {
Log.d(Constants.TAG, "Swipe +");
}
@Override
public void onDragStateChanged(int state) {
}
});
}
示例2: subscribeActual
import android.support.design.widget.SwipeDismissBehavior; //导入依赖的package包/类
@Override protected void subscribeActual(Observer<? super View> observer) {
if (!checkMainThread(observer)) {
return;
}
if (!(view.getLayoutParams() instanceof LayoutParams)) {
throw new IllegalArgumentException("The view is not in a Coordinator Layout.");
}
LayoutParams params = (LayoutParams) view.getLayoutParams();
final SwipeDismissBehavior behavior = (SwipeDismissBehavior) params.getBehavior();
if (behavior == null) {
throw new IllegalStateException("There's no behavior set on this view.");
}
Listener listener = new Listener(behavior, observer);
observer.onSubscribe(listener);
behavior.setListener(listener);
}
示例3: dismisses
import android.support.design.widget.SwipeDismissBehavior; //导入依赖的package包/类
@Test public void dismisses() {
((CoordinatorLayout.LayoutParams) view.getLayoutParams()).setBehavior(
new SwipeDismissBehavior());
RecordingObserver<View> o = new RecordingObserver<>();
RxSwipeDismissBehavior.dismisses(view)
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe(o);
o.assertNoMoreEvents(); // No initial value.
onView(withId(1)).perform(swipeRight());
assertEquals(view, o.takeNext());
o.dispose();
onView(withId(1)).perform(swipeRight());
o.assertNoMoreEvents();
}
示例4: onCreate
import android.support.design.widget.SwipeDismissBehavior; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_swipe_behavior);
final SwipeDismissBehavior swipe = new SwipeDismissBehavior();
swipe.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_ANY);
swipe.setListener(new SwipeDismissBehavior.OnDismissListener() {
@Override public void onDismiss(View view) {
Toast.makeText(SwipeBehaviorExampleActivity.this,
"Card swiped !!", Toast.LENGTH_SHORT).show();
}
@Override public void onDragStateChanged(int state) {}
});
CardView cardView = (CardView) findViewById(R.id.swype_card);
LayoutParams coordinatorParams = (LayoutParams) cardView.getLayoutParams();
coordinatorParams.setBehavior(swipe);
}
示例5: initBehavior
import android.support.design.widget.SwipeDismissBehavior; //导入依赖的package包/类
private void initBehavior() {
swipeDismissBehavior = new SwipeDismissBehavior();
swipeDismissBehavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_ANY);
swipeDismissBehavior.setListener(onDismissListener);
CoordinatorLayout.LayoutParams coordinatorParams = (CoordinatorLayout.LayoutParams) findViewById(R.id.textview).getLayoutParams();
coordinatorParams.setBehavior(swipeDismissBehavior);
swipeDismissBehavior.setDragDismissDistance(0.5F);
swipeDismissBehavior.setStartAlphaSwipeDistance(0F);
swipeDismissBehavior.setEndAlphaSwipeDistance(0.5F);
swipeDismissBehavior.setSensitivity(0);
swipeDismissBehavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_START_TO_END);
}
示例6: CardViewHolder
import android.support.design.widget.SwipeDismissBehavior; //导入依赖的package包/类
public CardViewHolder(final View itemView) {
super(itemView);
userName = (TextView) itemView.findViewById(R.id.user_name);
userIcon = (ImageView) itemView.findViewById(R.id.user_icon);
image = (ImageView) itemView.findViewById(R.id.image);
card = (CardView) itemView.findViewById(R.id.card);
card.setOnClickListener(this);
// ドラッグして消えるBehaviorを取り付ける。
// スワイプする要素は、親ビューがCoordinatorLayoutである必要がある。
SwipeDismissBehavior behavior = new SwipeDismissBehavior();
behavior.setStartAlphaSwipeDistance(0.1f);
behavior.setEndAlphaSwipeDistance(0.6f);
behavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_START_TO_END);
behavior.setListener(new SwipeDismissBehavior.OnDismissListener() {
@Override
public void onDismiss(View view) {
if (listener != null) {
listener.onCardDismiss(CardViewHolder.this);
}
}
@Override
public void onDragStateChanged(int state) {
if (listener != null) {
listener.onDragStateChanged(CardViewHolder.this, state);
}
}
});
final ViewGroup.LayoutParams cardViewLayoutParams = card.getLayoutParams();
((CoordinatorLayout.LayoutParams) cardViewLayoutParams).setBehavior(behavior);
}
示例7: isBeingDragged
import android.support.design.widget.SwipeDismissBehavior; //导入依赖的package包/类
/**
* @return if the view is being being dragged or settled by {@link SwipeDismissBehavior}.
*/
private boolean isBeingDragged() {
final ViewGroup.LayoutParams lp = mView.getLayoutParams();
if (lp instanceof CoordinatorLayout.LayoutParams) {
final CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) lp;
final CoordinatorLayout.Behavior behavior = layoutParams.getBehavior();
if (behavior instanceof SwipeDismissBehavior) {
return ((SwipeDismissBehavior) behavior).getDragState() != SwipeDismissBehavior.STATE_IDLE;
}
}
return false;
}
示例8: isBeingDragged
import android.support.design.widget.SwipeDismissBehavior; //导入依赖的package包/类
/**
* @return if the view is being being dragged or settled by {@link SwipeDismissBehavior}.
*/
private boolean isBeingDragged() {
final ViewGroup.LayoutParams lp = mView.getLayoutParams();
if (lp instanceof CoordinatorLayout.LayoutParams) {
final CoordinatorLayout.LayoutParams cllp = (CoordinatorLayout.LayoutParams) lp;
final CoordinatorLayout.Behavior behavior = cllp.getBehavior();
if (behavior instanceof SwipeDismissBehavior) {
return ((SwipeDismissBehavior) behavior).getDragState()
!= SwipeDismissBehavior.STATE_IDLE;
}
}
return false;
}
示例9: isBeingDragged
import android.support.design.widget.SwipeDismissBehavior; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private boolean isBeingDragged() {
final ViewGroup.LayoutParams lp = mView.getLayoutParams();
if (lp instanceof CoordinatorLayout.LayoutParams) {
final CoordinatorLayout.LayoutParams cllp = (CoordinatorLayout.LayoutParams) lp;
final CoordinatorLayout.Behavior behavior = cllp.getBehavior();
if (behavior instanceof SwipeDismissBehavior) {
return ((SwipeDismissBehavior) behavior).getDragState() != SwipeDismissBehavior.STATE_IDLE;
}
}
return false;
}
示例10: layoutDependsOn
import android.support.design.widget.SwipeDismissBehavior; //导入依赖的package包/类
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
if(dependency instanceof TopCardView) {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) dependency.getLayoutParams();
params.setBehavior(swipeDismissBehavior);
swipeDismissBehavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_START_TO_END);
swipeDismissBehavior.setStartAlphaSwipeDistance(0.1f);
swipeDismissBehavior.setEndAlphaSwipeDistance(0.9f);
swipeDismissBehavior.setDragDismissDistance(0.8f);
return true;
}
return false;
}
示例11: Listener
import android.support.design.widget.SwipeDismissBehavior; //导入依赖的package包/类
Listener(SwipeDismissBehavior swipeDismissBehavior, Observer<? super View> observer) {
this.swipeDismissBehavior = swipeDismissBehavior;
this.observer = observer;
}