How To Implement Click The Certain Area To Do To Action?
This is an example of facebook sliding menu. When sliding, there is 20% space user can see which is similar with facebook. Facebook implements it with clicking anywhere of this 20%
Solution 1:
One way of doing that is as following with OnTouchListener on your activity. You can detect exactly where is touched on the screen.
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;
import android.widget.Toast;
publicclassAndroidTestActivityextendsActivityimplementsOnTouchListener {
LinearLayout main;
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
main = (LinearLayout) findViewById(R.id.main_layout);
main.setOnTouchListener(this); // you need to set the touch listener for your view. And every element around the detection area.
}
publicbooleanonTouch(View v, MotionEvent e) {
if(e.getX() <= main.getWidth() / 5) {
Toast.makeText(this, "In the %20..", Toast.LENGTH_SHORT).show();
returntrue;
}
returnfalse;
}
}
You also need to id your main layout
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/main_layout"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" >
Post a Comment for "How To Implement Click The Certain Area To Do To Action?"