android - widget attached to a screen border - android

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.

Related

Android Constraint layout - fix view to bottom of page AND below another view (while not being in between)

I have a ConstraintLayout that's within a NestedScrollView. At the bottom of this ScrollView (which has fillViewport="true") I always want a button. So I set my button to be app:layout_constraintBottom_toBottomOf="parent" and it is correctly fixed to the bottom. However, I have an expandable RecyclerView that covers up the button when expanded, since there are no constraints set between the button and the list. If I add app:layout_constraintTop_toBottomOf="#id/expandableRecyclerView", the button no longer gets covered - however the button is no longer fixed to the bottom of the page, it lays between the unexpanded list and the bottom of the page.
How can I set these two constraints, but tell the button to prefer being constrained to the bottom of the view? Below you can see the image of the button placed in between with the two constraints. I want it to be fixed to the bottom.
Thanks.
Well, sorry for posting. After 5 more minutes of tinkering I found that setting app:layout_constraintVertical_bias="1" fixes my problem.

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

How to Create menu top and bottom both of them in Android?

I wanna create a menu that be seen when clicked on the center of screen like Aldiko.
I've tested PopupWindow for create menu items but I didn't any solution for trackbar.
Are there any solutions?
Using Default Menu you can create Bottom or TOP layout. So you cant used this. But you can create your own layouts. Align one layout to top & second to bottom. Initially did INVISIBLE both layouts, when you click on center then VISIBLE both layouts.
You can use split ActionBar for getting something like you want. The only repercussion of using it will be the look in different screen modes (portrait and landscape). Your action items will align themselves as per the available screen space. Let me know if you are looking for some code for doing it with ActionBar.
You can use FrameLayout and put the main app layout on back frame and menu (with transparent background) on the top frame. Initial set the visibility of the menu layout to invisible so you app main layout would only be visible. Now when you clicks on the main layout just change the visibility to visible, when user press again set the top layout again to invisible.

How to lay a layout over another android

I've followed this guide to make the sliding menu like the facebook app has.
When the Button is pressed, a new Layout shows from the left of the screen. But it pushes the orginal Layout with elements to the right of the screen. How can I make the Layout lay over the orginal Layout?
See the link for code samples. Thanks!
Let me rephrase my question
When I press the button, the text of the button, and the button itself will be pushed to one side, and aligned vertically. How can I just push the button "out of the screen"
To overlap layout/views above each other, you need to use FrameLayout. It sets the visibility of view (e.g. z-index in CSS) in the order as they are defined.
Sounds like you are adding the new layout to the parent layout which is why its pushing the original layout out of the way. You need to add the new layout to the original layout and it will lay in the original layout.

How to shift parent layout to right without changing inner components layout?

In my application I want to have sliding menu on the left side just like facebook.
In my previous question I had raised concern regarding the same and thanks to this answer that I could found a way to slide my layout to right using this library. But, I found that, the library does not actually slides the layout, instead it just takes the screenshot and slides the image towards right as the components on the layout are not clickable. And I need those components to be clickable. So, I tried a new way of achieving this by putting the slideout menu on the left by keeping its default visibility to View.GONE and make it visible on click on left top corner "Show/hide Menu" button as shown in figure below.
Layout before:
Now when I click "Show/Hide Menu" button, the layout is something like-
Layout after:
As you can see, the layout on the right shrinks and so the button "Some other view" changes its width even if I've set the android:minWidth attribute to those two buttons on the right as well as its parent RelativeLayout.
So my question is, is there any way to shift the layout towards right without the inner components changing their width/layout? So in whatever area is available for my view, it will be filled by whatever portion of the content that can be filled in in that area.
This problem can be solved like this:
create framelayout with inside: first left menu with 3 buttons and second layout that contains other two buttons (show/hide and other view). This way, the second layout is in front of menu (since it is fill_parent).
in onClick of show/hide button perform translate animation: assuming that your menu is 200px wide, move the second layout by 200 to the right.
in onAnimationEnd, set margins to the second layout like this: secondLayoutLayoutParams.setMargins(200, 0, -200, 0);
Closing menu is similar: move the second layout to the left by 200 and set all margins to 0.
By setting margins you will avoid button shrinking.
Hope it helps
#Rajkiran - I have a root layout, that contains my left & right layouts.
My right layout has layout_height set to 'match_parent' & layout_widht is also set to 'match_parent'
Now when my left sliding panel appears on button click, I reset the width & height of my right layout programmatically to match the width & height of the root layout.
This perfectly shifts the right layout towards right without the inner components wrapping up.
To change height & width programatically I used this -
rootLayoutParams = new LayoutParams(rootLayout.getWidth(), rootLayout.getHeight());
rightLayout.setLayoutParams(rootLayoutParams);
Hope it helps you as well.

Categories

Resources