0
在我的Android應用程序,我有3個全屏ImageButtons(水平內的LinearLayout),我已經隱藏狀態欄(全屏幕應用程序)Android的顯示狀態欄點擊按鈕
的問題是,當我向下滑動顯示在狀態欄,在頂部的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);
}
}
你不明白的問題,這裏的目標是消除這個錯誤:刷卡顯示狀態欄時 在全屏模式下(狀態欄不可見)--->點擊一個按鈕。 現在如何防止點擊,如果有刷卡,而不是簡單的觸摸 –
這正是我回答。你需要'消費'刷卡。 – rushi
沒有工作的傢伙,我認爲問題是,當第一次點擊是在屏幕的最頂部邊緣,並且狀態欄出來沒有被應用程序的onTouchEvent檢測到,因此第二次點擊按鈕,被檢測爲第一次點擊(根據應用程序) –