How to use whole screen as button in android? - android

How can i get an onClick response when the user touches any part of the screen?

Place a Button inside the layout manager.
and specify
fill_parent
for width and height.
and remove the border of the button.
this will work.

For Example you have ah RelativeLayout means,
RelativeLayout mLyout=(RelativeLayout)findViewById(R.id.layout01);
relativeclic1.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
// Here do your Task
}
});

You can cut off the touch events before they are ever dispatched by overriding dispatchTouchEvent:
https://developer.android.com/reference/android/app/Activity.html#dispatchTouchEvent(android.view.MotionEvent)
You can get the statistics of the touch -- first, repeated, etc -- from the MotionEvent passed.

Related

ClickListener in ScrollView intercepts scrolling

I have two rows of imageViews in a ScrollView. The imageViews all have onClickListener and when i want to scroll in this area it doesn't work. So i guess the Click listeners intercept the scrolling of the ScrollView. What's the best way to change this behaviour ?
My View hierarchy is like this:
<ScrollView>
<RelativeLayout>
<FrameLayout>
</FrameLayout>
<RelativeLayout>
</ScrollView>
in the FrameLayout i put a Fragment which has a LinearLayout in which i inflate other LinearLayouts like this:
productHolder.productLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View v) {
}
});
Maybe you could use an OnTouchListener instead of an OnClickListener.
In the OnTouchListener you can check if the action of the motion event was a click and consume the event (return true). Otherwise you can leave the event for other listeners (return false) to consume.
Note, that you might need to add some additional implementation for figuring out which image view was clicked, however without seeing your layout, it's hard to give you a hint how to do it.

Touch a button behind an invisible view

See the picture, i have a button and it is behind an invisible view (the red line), lets say a gridview, or just simply LinearLayout. Is there any possible way that will let me touch or click the button behind this invisible view? Thank you.
NOTE : i have my reason why i need the button behind the view, i just illustrated it using this picture for you guys to know what i meant. The button has to behind the view :))
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
Declare it in your layout.
Let me know if it helps you.
Yes Its possible. Until or unless your invisible view is not clickable. so check your invisible layout structure. make android:clickable="false"
1 way you can do this is:
1. add an onTouch(View view, MotionEventevent) Listener to your layout
2. get the buttons bounds
3. Check if the touch event was done inside the bounds
The code should look something like this:
Button button;
Rect rect;
onCreate(){
rect = button.getClipBounds();
layout.setOnTouchListener(this)
}
onTouch(View view, MotionEvent event){
if(rect.contains(event.getX(), event.getY())
//insert action here
}

Making custom android views "tappable" with a feedback highlight

I'm using a custom view expanded from a XML layout in a horizontal scroll view as a sort of horizontal image list but I'm not sure how to get them to appear clickable/tappable (ie they highlight when tapped) or how to capture these events. I think I've tried setOnClickHandler without it working. I'm also trying to get a simple TextView to do the same. I've also tried setting android:clickable="true" but that hasn't helped either. Any ideas?
To take care of the visual feedback use an xml Selector, and set it as the View's background.
To handle click events use
mView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//your code here
}
});

how to zoom-in interface? Android development

In my Android application, I have an activity with three layouts: A left layout, a middle layout, and a right layout.
The right layout is the main one. I want the right layout to zoom into fullscreen when I click a button. If you have the specific code,it's better.
Thanks very much!
If I got your question right:
Your button's OnClickListener should look like something like this:
OnClickListener listener = OnClickListener() {
public void onClick(View v){
findViewById(R.id.left_layout).setVisibility(View.INVISIBLE);
findViewById(R.id.center_layout).setVisibility(View.INVISIBLE);
};
This by itself will not get your right layout to fullscreen. You'll need to add something the below to your right layout for it to "auto fullscreen":
android:layout_width = "0dp";
android:layout_weight = "1";
if you don't do that, you'll have to resize the right layout from the "listener" above.
Hmm, the question is vague, but if I understand correctly, what you want to do is hide the left and center layouts when a button is clicked, so that the right layout becomes full-screen?
Without more details, it's not easy to give you a more precise answer (please post your current layout), but I would do something like:
// this code in your Activity:
// this method is bound to button onCLick (android:onClick="clickButton")
public void clickButton(View view) {
findViewById(R.id.left_layout).setVisibility(View.INVISIBLE);
findViewById(R.id.center_layout).setVisibility(View.INVISIBLE);
}
And to revert back to a 3-layout display, you do the opposite (View.VISIBLE)

Starting an activity when tapping on a widget

I'm developing an android widget and i would like to start a certain activity when i tap on a certain area of my widget, and another one when tapping somewhere else.
How can i do this ?
Thank you!
Create 2 Linear Layouts in places wherever you want to touch, and let them be blank (No child).
Then add android:clickable = "true" in linear layouts. and now add clicklisteners to thes two layouts and start Activity..
Something like this..
LinearLayout layout = (LinearLayout)findViewById(R.id.layoutId);
layout.setOnClickListener(new OnClickListener(){
protected void onClick(View v){
//start Activity
}
});

Categories

Resources