手机能连到无线网卡搜索不到信号信号,为什么上不了网,IP什么的都正常,

16855人阅读
Android(13)
& & & & 最近要实现一个长按录音,松开手指结束录音的功能,在项目中,弄来弄去绕晕了,写个demo来梳理下。顺便研究下android事件调用机制。
& 先上效果界面:
&RelativeLayout xmlns:android=&/apk/res/android&
xmlns:tools=&/tools&
android:layout_width=&match_parent&
android:layout_height=&match_parent&&
android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:id=&@+id/btn&
android:layout_centerInParent=&true&
android:background=&@drawable/microp_btn_normal& /&
&/RelativeLayout&
package com.example.
import android.os.B
import android.util.L
import android.view.LayoutI
import android.view.MotionE
import android.view.V
import android.view.View.OnClickL
import android.view.View.OnLongClickL
import android.view.View.OnTouchL
import android.widget.B
import android.widget.ImageV
import android.app.A
import android.app.D
import android.content.I
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.btn);
btn.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
Log.d(&TAG&, &onTouch is called.............&);
btn.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View arg0) {
Log.d(&TAG&, &onLongClick is called.............&);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d(&TAG&, &onClick is called.............&);
在代码中,我们监听了onTouch、onLongClick、onClick事件,其中onTouch和OnLongClick有返回值,onClick没有返回值。
现运行以上代码,长按按钮,我们可以看到调用顺序为
onTouch-&onLongClick-&onClick
现将OnTouch的返回值改为true,可发现onLongClick和onClick事件没有调用。说明onTouch返回true,后续事件没有传递。
接下来我们看下onTouch具体触发了哪些事件(只长按)
btn.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
//Log.d(&TAG&, &onTouch is called.............&);
switch (arg1.getAction()) {
case MotionEvent.ACTION_DOWN:
Log.d(&TAG&, &ACTION_DOWN.............&);
case MotionEvent.ACTION_MOVE:
Log.d(&TAG&, &ACTION_MOVE.............&);
case MotionEvent.ACTION_CANCEL:
Log.d(&TAG&, &ACTION_CANCEL.............&);
case MotionEvent.ACTION_UP:
Log.d(&TAG&, &ACTION_UP.............&);
看下日志截图
我只是按住,并未滑动。
我们将onLongClick返回true,可以预见,onClick事件不会被触发。但ACTION_UP呢?
经验证ACTION_UP被触发了。
接下来我们换下布局文件:
&ScrollView xmlns:android=&/apk/res/android&
xmlns:tools=&/tools&
android:layout_width=&match_parent&
android:layout_height=&match_parent&&
&LinearLayout android:layout_width=&match_parent&
android:layout_height=&match_parent&
android:orientation=&vertical&&
&View android:layout_width=&match_parent&
android:layout_height=&1000dp&/&
android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:id=&@+id/btn&
android:layout_gravity=&center_horizontal&
android:background=&@drawable/microp_btn_normal& /&
&/LinearLayout&
&/ScrollView&
意图很简单,让我们的按钮在滚动条的底部,日志截图
& 这时,我们的ACTION_UP没被触发,最后触发的是ACTION_CANCLE,而且我按了好几次才让它触发onLongClick事件,大多数只触发了DOWN/MOVE/CANCLE事件。
我怀疑是ScrollView滑动事件与onTouch事件冲突
在onTouch加上一句防冲突代码
btn.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
//Log.d(&TAG&, &onTouch is called.............&);
arg0.getParent().requestDisallowInterceptTouchEvent(true);//通知父控件勿拦截本控件touch事件
switch (arg1.getAction()) {
case MotionEvent.ACTION_DOWN:
Log.d(&TAG&, &ACTION_DOWN.............&);
case MotionEvent.ACTION_MOVE:
Log.d(&TAG&, &ACTION_MOVE.............&);
case MotionEvent.ACTION_CANCEL:
Log.d(&TAG&, &ACTION_CANCEL.............&);
case MotionEvent.ACTION_UP:
Log.d(&TAG&, &ACTION_UP.............&);
btn.setBackgroundResource(R.drawable.microp_btn_normal);
arg0.getParent().requestDisallowInterceptTouchEvent(true);//通知父控件勿拦截本控件touch事件
这样我们就和我们预期一样。
因为我的长按录制音频在ScrollView中,没有做onTouch冲突处理,所以出现很多莫名其妙的问题。
现在要实现我们的要求,只要在onLongClick中录制,ACTION_UP结束即可。
demo下载:
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:122900次
积分:1415
积分:1415
排名:千里之外
原创:21篇
评论:52条
(1)(2)(1)(1)(1)(3)(1)(2)(3)(5)(1)本帖子已过去太久远了,不再提供回复功能。Android处置滑动与点击事件的冲突 - Android当前位置:& &&&Android处置滑动与点击事件的冲突Android处置滑动与点击事件的冲突&&网友分享于:&&浏览:0次Android处理滑动与点击事件的冲突需求:一个ViewGroup中有多个控件,类似于常见的底部Tab布局,这几个子布局之间既可以点击切换,也可以左右滑动切换
实现:自定义父控件,在onInterceptTouchEvent方法中判断是否点击还是滑动,如果判断是点击,则直接交给child来响应点击事件去;如果是滑动,则
拦截事件,并通过回调传递给调用者处理。
优点:该控件只对触摸事件的分发做了相应处理,适用于各种滑动与点击冲突的情况....
使用:直接将该控件作为父布局即可,通过setmSetOnSlideListener回调处理对应滑动事件
import android.content.C
import android.util.AttributeS
import android.view.MotionE
import android.view.ViewC
import android.widget.RelativeL
public class MyRadioRelativeLayout extends RelativeLayout {
public MyRadioRelativeLayout(Context context) {
this(context, null);
public MyRadioRelativeLayout(Context context, AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView();
public MyRadioRelativeLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
private void initView() {
private boolean mS
private float touchDownX;
public boolean onInterceptTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touchDownX = event.getX();
mScrolling = false;
case MotionEvent.ACTION_MOVE:
if (Math.abs(touchDownX - event.getX()) &= ViewConfiguration.get(
getContext()).getScaledTouchSlop()) {
mScrolling = true;
mScrolling = false;
case MotionEvent.ACTION_UP:
mScrolling = false;
float x1 = 0;
float x2 = 0;
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
return true;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
x2 = event.getX();
if (touchDownX - x2 & DensityUtil.dip2px(getContext(), 40)) {
if(mSetOnSlideListener!=null){
mSetOnSlideListener.onRightToLeftSlide();
if (touchDownX - x2 & -DensityUtil.dip2px(getContext(), 40)) {
if(mSetOnSlideListener!=null){
mSetOnSlideListener.onLeftToRightSlide();
return super.onTouchEvent(event);
private setOnSlideListener mSetOnSlideL
public setOnSlideListener getmSetOnSlideListener() {
return mSetOnSlideL
public void setmSetOnSlideListener(setOnSlideListener mSetOnSlideListener) {
this.mSetOnSlideListener = mSetOnSlideL
public interface setOnSlideListener{
void onRightToLeftSlide();
void onLeftToRightSlide();
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 1234567891011 Copyright & &&版权所有

我要回帖

更多关于 手机搜不到无线信号 的文章

 

随机推荐