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)
Related
I was wondering if someone can advise what the best way to do the following: I'm creating an application where I'm asking the user a question and the user either answers the question or proceeds to the next question with fade in and fade out animation using animator instead of anim. As of now, I have one activity and in the activity I would load the layout that I have created in XML and then remove the view and load a new view.
I'm not sure if this is the best way to present multiple views in one Activity and prevent the need to use multiple activities. The reason why I'm doing this is because I have several objects that I'm storing data into based on the category of the question (whether is math, science, social studies, etc).
Here is a picture if it helps visualize:
If there is a better way to do this, please let me know. The only issue I'm having with this is that the activity A java class is growing in code because I have to handle everything there despite having the classes of the objects defined in other java files. Thank you.
I think you can build layout like this
RelativeLayout(see the structure) Set layout1 android:visibility="visible" and layout2 android:visibility="invisible" at first in .xml
layout1 = findViewById(R.id.layout1);
layout1.setVisibility(View.VISIBLE);
layout2 = findViewById(R.id.layout2);
layout2.setVisibility(View.GONE);
Button buttonNext = (Button)findViewById(R.id.buttonNext);
buttonNext.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
layout1.setVisibility(View.GONE);
layout2.setVisibility(View.VISIBLE);
viewTransAnimation();
}
});
And set your animation in viewTransAnimation(), example:
private void viewTransAnimation() {
layout2.setScaleX(0.1f);
layout2.setPivotX(layout2.getX() + layout2.getLeft() );
layout2.animate()
.scaleX(1)
.setDuration(500)
.setInterpolator(new AccelerateInterpolator())
.start();
}
Then it will change to layout2 after you click it. (use some flag make the animation only work once for your requirement.)
You can also replace 2 view with 2 RelativeLayout and do it in the same way.
I'm trying to create a RadioGroup with RadioButtons that have more than text only.
The image below will make things easier to understand.
I want the RadioButton to be selected when the user clicks somewhere in the layout around it.
I've tried do do somthing lik this:
<RadioGroup>
<RelativeLayout>
<RadioButton>
<...other stuff>
</RelativeLayout>
</RadioGroup>
But that didn't work.
Does somebody know how to easily get the requested layout and behaviour? Thanks
EDIT:
I forgot to mention that I don't want to use a list. I want all items to be visible because there are maximum three. Also, the container is a ScrollView
As Der Golem said you can use ListView and set it to be in a single choice mode: list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
But if you need only few layouts you can register Click listener to your layouts and call onClick events on RadioButtons:
bigLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
radioButton.performClick();
}
});
Hope it will help
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.
I'm translating an image from somewhere to another, and where it goes there is a button. But i want it to be unclickable when the image's over it! It's not seen but still can be clicked! How can i bring the image to front, so the button will not be worked? Thanks in advance.
Implement setAnimationListener in your translate animation and in onAnimationStart(Animation animation) put your bringToFront() method. It does work for me.
Try this:
Button btn = (Button)findViewById(R.id.my_btn);
btn.setEnabled(false);
I think it could help if you make that the ImageView clickable.
This could be achieved by:
Setting the clickable attribute (http://developer.android.com/reference/android/view/View.html#attr_android:clickable) to true in the layout XML
Invoking setClickable(true) (http://developer.android.com/reference/android/view/View.html#setClickable%28boolean%29) on the ImageView object in your code
Change the order of your xml file. The Views that are listed first will be behind the Views that are listed after them.
<ImageView android:id="#+id/iv01"/>
<Button android:id="#+id/btn01"/>
In the code above the button will be placed on top of the ImageView.
<Button android:id="#+id/btn01"/>
<ImageView android:id="#+id/iv01"/>
In the code above the ImageView will be placed on top of the Button.
You can also hide the Button from the layout in your .java (Activity) file.
Button btn = findViewById(R.id.btn01);
btn.setVisibility(View.GONE);
Also you can set the Butt
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
}
});