あなたは完璧なアンドロイドジェスチャーをするために、次のコードを使用することができます。Main_activity.javaで
次のコードを入力:
package com.androidtutorialpoint.myapplication;
public class MainActivity extends AppCompatActivity implements
GestureDetector.OnGestureListener,
GestureDetector.OnDoubleTapListener {
private TextView output_text;
private GestureDetectorCompat DetectMe;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
output_text = (TextView) findViewById(R.id.outputText); // Taking reference of text to be displayed on screen
DetectMe = new GestureDetectorCompat(this,this);
DetectMe.setOnDoubleTapListener(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
// Following functions are overrided to show text when a particular method called.
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
output_text.setText("onSingleTapConfirmed");
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
output_text.setText("onDoubleTap");
return true;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
output_text.setText("onDoubleTapEvent");
return true;
}
@Override
public boolean onDown(MotionEvent e) {
output_text.setText("onDown");
return true;
}
@Override
public void onShowPress(MotionEvent e) {
output_text.setText("onShowPress");
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
output_text.setText("onSingleTapUp");
return true;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
output_text.setText("onScroll");
return true;
}
@Override
public void onLongPress(MotionEvent e) {
output_text.setText("onLongPress");
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
output_text.setText("onFling");
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event){
this.DetectMe.onTouchEvent(event);
return super.onTouchEvent(event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
これだけのButton1に取り組んでいます。 – johnyX
それから私にあなたを見せてくれるように追加してください。 –
はい私は知っていますが、それはまさに私が避けたかったものです。レイアウトには多くのアイテムがあり、これをx回作成する必要があります。 – johnyX