本文整理汇总了Java中android.view.ViewGroup.setOnTouchListener方法的典型用法代码示例。如果您正苦于以下问题:Java ViewGroup.setOnTouchListener方法的具体用法?Java ViewGroup.setOnTouchListener怎么用?Java ViewGroup.setOnTouchListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.ViewGroup
的用法示例。
在下文中一共展示了ViewGroup.setOnTouchListener方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateView
import android.view.ViewGroup; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup view = (ViewGroup) inflater.inflate(R.layout.fragment_square, container, false);
mCardView = (CardView) view.findViewById(R.id.card_view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mCardZ = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2.f, getResources().getDisplayMetrics());
mCardView.setZ(mCardZ);
}
final ViewDragHelper viewDragHelper = ViewDragHelper.create(view, mViewDragHelperCallback);
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
viewDragHelper.processTouchEvent(event);
return false;
}
});
recordOriginalLocation(mCardView);
return view;
}
示例2: init
import android.view.ViewGroup; //导入方法依赖的package包/类
public void init(Context context) {
View.inflate(context, getLayoutId(), this);
startButton = (ImageView) findViewById(R.id.start);
fullscreenButton = (ImageView) findViewById(R.id.fullscreen);
progressBar = (SeekBar) findViewById(R.id.bottom_seek_progress);
currentTimeTextView = (TextView) findViewById(R.id.current);
totalTimeTextView = (TextView) findViewById(R.id.total);
bottomContainer = (ViewGroup) findViewById(R.id.layout_bottom);
textureViewContainer = (ViewGroup) findViewById(R.id.surface_container);
topContainer = (ViewGroup) findViewById(R.id.layout_top);
startButton.setOnClickListener(this);
fullscreenButton.setOnClickListener(this);
progressBar.setOnSeekBarChangeListener(this);
bottomContainer.setOnClickListener(this);
textureViewContainer.setOnClickListener(this);
textureViewContainer.setOnTouchListener(this);
mScreenWidth = getContext().getResources().getDisplayMetrics().widthPixels;
mScreenHeight = getContext().getResources().getDisplayMetrics().heightPixels;
mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mHandler = new Handler();
}
示例3: cleanup
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* Clean-up the resources attached to this object. This needs to be called when the zoomLayout is
* no longer used. A good example is from {@link android.view.View#onDetachedFromWindow()} or
* from {@link android.app.Activity#onDestroy()}. This is automatically called if you are using
* {@link DragPhotoView}.
*/
public void cleanup() {
if (null == zoomLayout) {
return; // cleanup already done
}
final ViewGroup view = zoomLayout.get();
if (null != view) {
// Remove the zoomLayout's reference to this
view.setOnTouchListener(null);
}
if (null != gestureDetector) {
gestureDetector = null;
}
// Finally, clear zoomLayout
zoomLayout = null;
}
示例4: init
import android.view.ViewGroup; //导入方法依赖的package包/类
public void init(Context context) {
View.inflate(context, getLayoutId(), this);
startButton = (ImageView) findViewById(R.id.start);
fullscreenButton = (ImageView) findViewById(R.id.fullscreen);
progressBar = (SeekBar) findViewById(R.id.progress);
currentTimeTextView = (TextView) findViewById(R.id.current);
totalTimeTextView = (TextView) findViewById(R.id.total);
bottomContainer = (ViewGroup) findViewById(R.id.layout_bottom);
textureViewContainer = (ViewGroup) findViewById(R.id.surface_container);
topContainer = (ViewGroup) findViewById(R.id.layout_top);
startButton.setOnClickListener(this);
fullscreenButton.setOnClickListener(this);
progressBar.setOnSeekBarChangeListener(this);
bottomContainer.setOnClickListener(this);
textureViewContainer.setOnClickListener(this);
textureViewContainer.setOnTouchListener(this);
mScreenWidth = getContext().getResources().getDisplayMetrics().widthPixels;
mScreenHeight = getContext().getResources().getDisplayMetrics().heightPixels;
mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mHandler = new Handler();
}
示例5: init
import android.view.ViewGroup; //导入方法依赖的package包/类
public void init(Context context) {
View.inflate(context, getLayoutId(), this);
startButton = (ImageView) findViewById(R.id.start);
fullscreenButton = (ImageView) findViewById(R.id.fullscreen);
progressBar = (SeekBar) findViewById(R.id.bottom_seek_progress);
currentTimeTextView = (TextView) findViewById(R.id.current);
totalTimeTextView = (TextView) findViewById(R.id.total);
bottomContainer = (ViewGroup) findViewById(R.id.layout_bottom);
textureViewContainer = (ViewGroup) findViewById(R.id.surface_container);
topContainer = (ViewGroup) findViewById(R.id.layout_top);
startButton.setOnClickListener(this);
fullscreenButton.setOnClickListener(this);
progressBar.setOnSeekBarChangeListener(this);
bottomContainer.setOnClickListener(this);
textureViewContainer.setOnClickListener(this);
textureViewContainer.setOnTouchListener(this);
mScreenWidth = getContext().getResources().getDisplayMetrics().widthPixels;
mScreenHeight = getContext().getResources().getDisplayMetrics().heightPixels;
mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mHandler = new Handler();
NORMAL_ORIENTATION = context.getResources().getConfiguration().orientation;
}
示例6: SlideDrawerHelper
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* @param builder SlideDrawerHelper建造者
*/
private SlideDrawerHelper(@NonNull Builder builder) {
ViewGroup dragLayout = builder.dragLayout;// 滑动触发布局,可拖动或点击
this.slideParentLayout = builder.slideParentLayout;
this.minHeight = builder.minHeight;
this.mediumHeight = builder.mediumHeight;
this.maxHeight = builder.maxHeight;
this.animDuration = builder.animDuration;
this.removeMediumHeightState = builder.removeMediumHeightState;
this.clickSlidable = builder.clickSlidable;
this.mediumClickSlideState = builder.mediumClickSlideState;
dragLayout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
handleSlide(event);
return true;
}
});
}
示例7: init
import android.view.ViewGroup; //导入方法依赖的package包/类
public void init(Context context) {
View.inflate(context, getLayoutId(), this);
startButton = (ImageView) findViewById(R.id.start);
fullscreenButton = (ImageView) findViewById(R.id.fullscreen);
progressBar = (SeekBar) findViewById(R.id.progress);
currentTimeTextView = (TextView) findViewById(R.id.current);
totalTimeTextView = (TextView) findViewById(R.id.total);
bottomContainer = (ViewGroup) findViewById(R.id.layout_bottom);
textureViewContainer = (ViewGroup) findViewById(R.id.surface_container);
topContainer = (ViewGroup) findViewById(R.id.layout_top);
titleTextView = (TextView) findViewById(R.id.title);
backButton = (ImageView) findViewById(R.id.back);
backButton.setVisibility(View.GONE);
backButton.setOnClickListener(this);
startButton.setOnClickListener(this);
fullscreenButton.setOnClickListener(this);
progressBar.setOnSeekBarChangeListener(this);
bottomContainer.setOnClickListener(this);
textureViewContainer.setOnClickListener(this);
textureViewContainer.setOnTouchListener(this);
mHandler = new Handler();
}
示例8: onCreateView
import android.view.ViewGroup; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = (ViewGroup) inflater.inflate(R.layout.fragment_tap_to_move_demo, container, false);
animatedView = rootView.findViewById(R.id.animated_view);
rootView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
AdditiveAnimator.cancelAnimation(animatedView, View.ROTATION);
}
return true;
}
});
animate();
return rootView;
}
开发者ID:wirecube,项目名称:android_additive_animations,代码行数:20,代码来源:RepeatingChainedAnimationsDemoFragment.java
示例9: onCreateView
import android.view.ViewGroup; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = (ViewGroup) inflater.inflate(R.layout.fragment_margins_demo, container, false);
animatedView = rootView.findViewById(R.id.animated_view_with_margins);
rootView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_DOWN) {
if(AdditiveAnimationsShowcaseActivity.ADDITIVE_ANIMATIONS_ENABLED) {
AdditiveAnimator.animate(animatedView).leftMargin((int) event.getX()).topMargin((int) event.getY()).start();
} else {
ViewPropertyObjectAnimator.animate(animatedView).leftMargin((int) event.getX()).topMargin((int) event.getY()).setInterpolator(EaseInOutPathInterpolator.create()).setDuration(1000).start();
}
}
return true;
}
});
return rootView;
}
示例10: initGrid
import android.view.ViewGroup; //导入方法依赖的package包/类
private void initGrid() {
ViewGroup viewGroup;
for (int i = 0; i < mWeekInfoList.size(); i++) {
viewGroup = mView_Column.get(i);
if (viewGroup == null) return;
viewGroup.removeAllViews();
final int index = i;
viewGroup.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return checkGridClick(event, index, (ViewGroup) v);
}
});
}
}
示例11: initViewWithId
import android.view.ViewGroup; //导入方法依赖的package包/类
private void initViewWithId(Context context) {
mContext = context;
LayoutInflater inflater =
(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.tag_root, this);
mRoot = (ViewGroup) findViewById(R.id.tag_root);
mTagImageView = (TagImageView) findViewById(R.id.tag_image_view);
setLayoutParamsToBeSetForRootLayout(mContext);
mRoot.post(mSetRootHeightWidth);
mRoot.setOnTouchListener(mTagOnTouchListener);
mGestureDetector = new GestureDetector(mRoot.getContext(), mTagGestureListener);
}
示例12: init
import android.view.ViewGroup; //导入方法依赖的package包/类
private void init() {
inflate(getContext(), R.layout.image_viewer, this);
backgroundView = findViewById(R.id.backgroundView);
pager = (MultiTouchViewPager) findViewById(R.id.pager);
dismissContainer = (ViewGroup) findViewById(R.id.container);
swipeDismissListener = new SwipeToDismissListener(findViewById(R.id.dismissView), this, this);
dismissContainer.setOnTouchListener(swipeDismissListener);
directionDetector = new SwipeDirectionDetector(getContext()) {
@Override
public void onDirectionDetected(Direction direction) {
ImageViewerView.this.direction = direction;
}
};
scaleDetector = new ScaleGestureDetector(getContext(),
new ScaleGestureDetector.SimpleOnScaleGestureListener());
gestureDetector = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
if (pager.isScrolled()) {
onClick(e, isOverlayWasClicked);
}
return false;
}
});
}
示例13: createFloatBox
import android.view.ViewGroup; //导入方法依赖的package包/类
private ViewGroup createFloatBox() {
Activity topActivity = PlayerManager.getInstance().getTopActivity();
ViewGroup topActivityBox = (ViewGroup) topActivity.findViewById(android.R.id.content);
ViewGroup floatBox = (ViewGroup) LayoutInflater.from(topActivity.getApplication()).inflate(R.layout.giraffe_float_box, null);
floatBox.setBackgroundColor(videoInfo.getBgColor());
FrameLayout.LayoutParams floatBoxParams = new FrameLayout.LayoutParams(400,300);
floatBoxParams.gravity = Gravity.BOTTOM | Gravity.END;
floatBoxParams.bottomMargin = 20;
floatBoxParams.rightMargin = 20;
topActivityBox.addView(floatBox,floatBoxParams);
floatBox.setOnTouchListener(new View.OnTouchListener() {
float ry;
float oy;
float rx;
float ox;
@Override
public boolean onTouch(View v, MotionEvent event) {
// 获取相对屏幕的坐标,即以屏幕左上角为原点
// System.out.println("MotionEvent:action:"+event.getAction()+",raw:["+event.getRawX()+","+event.getRawY()+"],xy["+event.getX()+","+event.getY()+"]");
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
ry = event.getRawY();
oy = v.getTranslationY();
rx = event.getRawX();
ox = v.getTranslationX();
break;
case MotionEvent.ACTION_MOVE:
float y = oy + event.getRawY() - ry;
if (y > 0) {
y = 0;
}
v.setTranslationY(y);
float x = ox + event.getRawX() - rx;
if (x > 0) {
x = 0;
}
v.setTranslationX(x);
break;
}
return true;
}
});
return floatBox;
}