【发布时间】:2017-06-27 11:12:11
【问题描述】:
在我的 android 应用程序中,我有 3 个全屏 ImageButtons(水平在 LinearLayout 内),并且我隐藏了状态栏(全屏应用程序)
问题是,当我向下滑动以显示状态栏时,顶部的 ImageButton 被点击,我尝试检测点击,所以如果它是滑动而不是像这样的点击,我会禁用按钮的功能
@Override
public boolean onTouchEvent(MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN :
y1 = event.getY();
i=0;
break;
case MotionEvent.ACTION_UP:
y2 = event.getY();
float deltaY = y2-y1;
if(deltaY < 10 && deltaY > -10)
{
flag=true;
}
else
{
flag=false;
}
break;
}
return super.onTouchEvent(event);
}
但它似乎不起作用。
任何帮助将不胜感激,在此先感谢您。
编辑 1:
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="3"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#567"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
style="?android:attr/buttonStyleSmall"
android:background="?android:attr/selectableItemBackground"
android:onClick="speech"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#456"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
style="?android:attr/buttonStyleSmall"
android:onClick="pics"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#345"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
style="?android:attr/buttonStyleSmall"
android:id="@+id/vids"
/>
</LinearLayout>
</LinearLayout>
Java:
public class BirthdayActivity extends AppCompatActivity {
private float x1,x2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_birthday);
}
public void speech(View v)
{
finish();
Intent intent = new Intent(BirthdayActivity.this , SpeechActivity.class);
BirthdayActivity.this.startActivity(intent);
}
public void pics(View v)
{
finish();
Intent intent = new Intent(BirthdayActivity.this , PicsActivity.class);
BirthdayActivity.this.startActivity(intent);
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN :
x1 = event.getY();
break;
case MotionEvent.ACTION_UP:
x2 = event.getY();
float Delta = x2-x1;
//if on actionUp, the distance is big == swipe
if(Delta < 5 && Delta(-5))
{
}
else
{
}
break;
}
return super.onTouchEvent(event);
}
}
【问题讨论】:
标签: java android button status