visibility of buttons and layout - android

I have 10*3 buttons on my screen. When I click a button, I want it to be unvisible, so I do :
arg0.setVisibility(View.GONE);
But whenever the button is gone, the buttons change their size.
For example, if at the begining every button took 1/3 of a row, now when a button is gone the other buttons in the row get wider..
Is there a way to make them not change their size when a button is removed?

Use View.INVISIBLE. Using GONE makes it as if it wasn't there (so it no longer takes up space). Invisible just makes it disappear.

Related

I can't see buttons in MaterialButtonToggleGroup

I want to use the toggle button group to make it look like the picture below.
enter image description here
However, if I insert a button into the toggleButton Group, the size of the button becomes very small. Even if the absolute size is given to each layout, only the size of the toggle Button Group is enlarged and the button inside is small, so I can't see it. When you take out the button, it returns to its normal size and you can see it well, but it looks small only in the group.
Can I know the reasons about this?
I am guessing that there must be separate styles in the toggleButton Group itself for buttons. Maybe you wanna check that.
Another reason I'm thinking is that maybe you have the width of the button set with % percentage, or with vh/vw(view height/width). If so button will change its size relative to the parent element size.

How to make another button appear when a first button is clicked and then allow it to disappear automatically when a second button is clicked?

I have a horizontal scroll with set of buttons at the top part of the screen. I want buttons to appear below when one of the buttons above are clicked.
Button button1=new Button(context);
button1.setText("test");
button1.setId(id);
containerlayout.add(button1);
You Must place your buttons on top as well as bottom and then need to set visibility on basis of your click event

Center the layout after hiding the Android button programmatically

I have one LinearLayout and it is center_horizontal.
It contains three buttons: left, middle and right. All were fixed in same row.
When I hide the right button programmatically it will hide the button, but not center the left and middle buttons.
I want the left and middle buttons to be centered in the layout when I am hiding the right button. Is this possible?
Making a view invisible, makes it only invisible which has its effect.
Try using gone instead of invisible and you are done!
Do the following settings:
1) Set visibitlity to gone
2) Set the width of ALL elements to 0dp and the weight of ALL to 1
Make sure that your three buttons are placed in LinearLayout with the orientation of horizontal, now use this code in Java file:
rightbutton.setVisibility(View.GONE);
Try this,
yourbutton.setVisibility(View.GONE);
What it does is, it stops the button from occupying any space on your screen which will in turn allow the other buttons to shift.
Just keeping it invisible will just hide the button from view, but it will still occupy the space and not allow the other buttons to adjust

Display rest of layout fields on button click on same View

I have layout containing 30 fields ( using editbox, spinners, buttons etc)
but it looks too weird with crowded elements. ( scroll view is also longer)
So i decided to keep 1 more button, so firstly 15 fields will display and 1 "More" button below,now i want to display rest of fields onClick "more" button on same layout ( below that 15 fields). How to do this, thanks in advance
I would suggest you to make a parent view with two main relative layouts. First relative layout for all the content you want to show at first time. Make this layout visibility View.VISIBLE. Second relative layout for all the content you want to show on click event. Make this layout visibility View.INVISIBLE.
On button click event make second relative layout visible by setting view.setVisibility(View.VISIBLE)
Don't forget the invisible the layout in the end. Otherwise it will be visible throughout the app session.
You can also set this property in your xml too. There is a android:visibility="visible" tag in every view.
This approach will help you in management because by setting a single view visibility you can manage your all view. Happy Coding!!

Button Click Delay inside ScrollView

I have an android activity that takes up more then the full screen so I place it inside a ScrollView. There is a button at the very bottom of my Activity and when I scroll down there is a delay in which I can click the button. The delay is until the scrollbar fades away and then the button can be clicked.
This is not a very long time, but for a user it may seem like it and it is very annoying so is there a way to make the buttons clickable while still scrolling or make that time shorter at least?

Categories

Resources