Set DialogFragment bottom margin according to calling activity - android

I have a DialogFragment that gets called from 1 of 4 buttons from a certain activity. Currently I have paddingBottom set to 48dp (height of these buttons) so the dialog pops up right above these buttons. But I've encountered a problem where on a really high res phone there's a gap between the dialog's bottom and the row of buttons.
Is there any way to either programmatically or through XML set the dialog right on top of calling activity button's height?

I did manage to solve the problem with setting the RelativeLayout height to fill_parent instead of fixed 460dp size. All of the children now use match_parent for height.

Related

How to adjust ConstraintLayout height with Recyclerview's height?

I want to have a recycler view with list of things of unknown number and a button below the RecyclerView. I want the height of the whole ConstraintLayout be flexible with the height of my RecyclerView, i.e. if the list is short, wrap content and if the list is long, just fill up the whole screen.
Now no matter how long the list is, the ConstraintLayout will fill up the whole screen . I have already had everything wrap_content but there is still blank space at bottom.I want my button always appear on the bottom. Does anyone know how to deal with this problem?
I guess you are trying to achieve this:
Your constraint layout will be the parent (root) with match parent for both width and height so it will take the whole screen.
Then put the button, the left and right sides should connect to the constraint layout sides, and the bottom of the button should connect with the bottom of the layout too (3 constraints only: right to right, left to left and bottom to bottom). Wrap content for both width and height.
The recyclerView will connect almost the same, top to top, left to left and right to right with the constraintLayout, but the bottom should connect with the top of your button. Finally select match parent for both width and weight.
On this way, your button will be always at the bottom of the screen and the recycler view height will go from top of the screen to top of your button.
If you want to change the constraints of your layout accordingly to some conditions (like reach specific number of items on your list) you need to do it programmatically.
Select by default your recycler view height as wrap_content, and on code write a method which observe every time an item is added or removed from your list. Create a conditional which says if the recyclerView.count( )== number and if it is true change the constraintLayout and child's constraints with something like this (example):
ConstraintLayout constraintLayout = findViewById(R.id.parent_layout);
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(constraintLayout);
constraintSet.connect(R.id.recycler,ConstraintSet.BOTTOM, R.id.button,ConstraintSet.TOP,0);
constraintSet.applyTo(constraintLayout);

Cannot change height of BottomSheetBehavior dynamically

When the button clicked, I want the height of Bottom Sheet change as seen in the image below. I tried multiple solutions none worked well.
Try doing something like:
Set the maximum height in XML and expand on button click
Call bottomsheet.setY(float)

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 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.

Android: Keeping Image Visible Throughout Animation

Background:
I have an Activity that comprises four buttons that each take up a quarter of the screen.
It contains a horizontal LinearLayout that is divided in half by two vertical LinearLayouts as shown in the image below:
http://i.stack.imgur.com/P7Wd3.jpg
Desired Effect:
When I touch a button, I would like it to animate and fill up the entire screen.
Issue:
I have accomplished the animation aspect by changing X and Y scales from 1 to 2 onClick.
The problem is, however, that the animated button will not show when it leaves its parent LinearLayout.
Thoughts
I have tried making the non-animated buttons invisible, but the animated button will only show in its parent LinearLayout.
I know this problem would be solved if I had used a single LinearLayout, but I was unable to use the "layout:weight" feature to make each button take up half of both width and length.
So... How should I approach this issue?
I would appreciate any help :)
Try using a single RelativeLayout. Check this post for a nice example. You may have to setVisibility(View.INVISIBLE) for the other buttons.
Alternative:
Construct a RelativeLayout as above but put that as the only child
of a FrameLayout.
When animating a button, remove it from the RelativeLayout and add it to the FrameLayout specifying the gravity in the LayoutParams appropriately. This way the rest of the buttons will also be seen in the background during the animation.

Categories

Resources