I have a fragment where I want to hide and reposition a few textviews and imagebuttons programatically in case they are empty but I also want to put the other two that are below them, on top of the screen where those were in the first place.
.setTop doesnt seem to do move the view
`if (tr.getName().isEmpty()) {
tv1.setVisibility(View.INVISIBLE);
tv2.setVisibility(View.INVISIBLE);
imgb1.setVisibility(View.INVISIBLE);
tv3.setVisibility(View.INVISIBLE);
tv4.setVisibility(View.INVISIBLE);
imgb2.setVisibility(View.INVISIBLE);
}`
I make those invisible but how do I set the other components on top of the screen, basically on top of those that are invisible?
You should use:
view.setVisibility(View.GONE)
instead :
view.setVisibility(View.INVISIBLE)
Related
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
I need to add a Button that is attached to the bottom of the screen so that it remain in that place when scrolling (other widgets move, but this don't). How to do it?
Put everything that you want to scroll in scrollview.
You want that button at the bottom of the layout. Set android:layout_alignParentBottom="true" in the xml of the button.
In my app I have a scroll view with n number of data to be listed out. There are two buttons one is named as UP placed above scroll view and the other is DOWN placed below scroll view.
Using the UP and DOWN buttons the list of views can be scrolled.
When the scroll bar is in top the Up button will be invisible and when the scroll bar reaches the bottom the DOWN button will become invisible, I have written logic for this using the getScrollX() method.
Now my problem is when there is very few data for example 3, the scroll bar will not be visible and the layout cannot be scrolled, in such a case both the UP and DOWN buttons need to be in invisible. How to do this, please suggest me a way?
You can try and use a ViewTreeObserver to check the dimension of the View inside your ScrollView. If the dimension exceeds a certain limit (such as the screen size), the ScrollView will be scrollable. See this preview SO answer for more details. Hope that helps!
I am having great trouble to implement layout swiping UI. Here I show you how each layout works.
My first Layout
My second layout
My third Layout
How it works:
A user can move one page to another by touching the screen and the indicator will move as the layout or page move. But the Sign In and Sign Up button will be fixed in there position. How can I implement this type of UI.
This can be done using a viewFlipper but there is a trick using this whole as a layout.
Use a frameLayout
having your buttons settled down with the gravity set to bottom
Note framelayout works as a stack LIFO things(widgets/layouts) placed at last will superimpose the ones place above them in xml
like for example
//so here view shows s2 and below that s1.....
so in your layout s2 will be the buttons with gravity as bottom
s1 -should be a viewFlipper ...
SWIPPING
swipping can be acheived using the onTouch event
SWIPE LEFT
When the touch down gives a position(x1,y1) and onTouchUp (x2,y2)
check if(x2>x1)
so use viewFlipper.setInAnimation(Animation) viewFlipper.setOutAnimation(Animation)--for the ui that will be gone
SWIPE RIGHT
similarly if (x2<x1)
viewFlipper.setInAnimation(Animation) viewFlipper.setOutAnimation(Animation)
You have used three different layout and increment counter by touching the layout and match to set the layout.
Here is the complete example of ViewFlow please check out the source
https://github.com/pakerfeldt/android-viewflow
and here is another example
http://developer.android.com/shareables/training/Animations.zip
see implementation of screen slide, that is what you exactly want.
The bar moves something like this
Display d= getWindowManager().getDefaultDisplay();
int h=d.getHeight();
int w=d.getWidth();
after getting this h and w , now at every swipe move the bar
where w=screen width calculated with the above method
increments=w/3;
bar_initial_position+=increments;
so it moves..
In my app I want to have a button that if the user clicks it
than a new layout is opened within the current (acually the main) layout.
the new layout should not fill all of the screen and parts of the previous layout
should be grayed out.
Any ideas on how to do this ?
You can show a hidden layout within your button's onClick event by calling
view.setVisibility(View.VISIBLE)
You can also fade out view elements or whole views with
view.setAlpha(75);
view.setBackgroundColor(Color.GRAY);
Note that "view" in the first example is your layout element.. LinearLayout, RelativeLayout, etc. and in the 2nd example, "view" is the element(s) you're trying to gray out.
Follow the answer of SBerg413. And for more information. you can take the relativelayout for the part that you want to hide and display on the button click.
And as like SBerg413 answer. you can hide the respective layout and show the layout you want to display.
Hope it will help you.
Thanks.
you can use a ViewFlipper to achieve what you want, position the viewflipper where the child views should fit (part of the screen you say)..
Inflate the rest of the "child" layouts from other xml, add them to the flipper and switch between them when you want...