I have multiple custom views rendered on my screen in RelativeLayout using LayoutParams. Now first time user touches on view it increase it's size, after that when user once again clicks on that view, that view should get disappear. Now the problem is when a view gets disappeared other views on screen changes their size and location. By debugging I found that this happens when I pass dynamic values as width and height in LayoutParams. If I go for static then all works good. But then I'm not able to increase the size of view. How can I solve this? I also tried changing View.GONE to View.INVISIBLE but that also doesn't help.
I create all views in code and place them on screen. In my xml I don not have any view entry. I do this because initial size of views should be random. So I create view and assign him initial size in LayoutParams(width, height) and then use topMargin and leftMargin to place them at various positions on screen. More details can be found here: Custom object click issue in android
Best guess without seeing any code... It sounds like you are using layout_weight, and if a view is removed, the other views with a layout_weight will expand to fill the now available space.
Related
I have a list item that contains an image (red) and another layout (blue)
Normally, the layout would be the first one, but the black layout's width depends on user configurations, so it may not fit the whole content.
I thought about making it a Linear Layout and changing the orientation depending on its width, but i read somewhere its possible to do such things with layout only (maybe constraint layouts).
Is it possible to achieve this result using only "layout responsiveness", or do i have to input some code also?
I'm trying to align some items inside a RecyclerView with others outside it. However, seems like all my tries are failing.
What I'm trying to do specifically: I have a couple of views as a header which are aligned using various methods* then a RecyclerView just below it, in its same parent, stretching the whole width, that inflates views.
The problem: Items inside the RecyclerView do not align perfectly to the items outside of it. Knowing that I'm using the same layout for both the parent and the items! And knowing that whatever method I used for horizontal alignment for the header items, is exactly used the same way for each item inflated for the RecyclerView. AND knowing that both items have same properties (they're TextViews, same size, width, height, etc...)
What methods have I tried? FOR BOTH SIDES (up and down), I tried the following:
Using ConstraintLayout for both parent and item layouts, and stretching the items between both start and end of parent, then using the constraint ratio to position it exactly where I want. Outcome for header is different from that of RecyclerView holders.
Using a TableLayout with children stretched across the whole width, same number of columns, same stretching, still different outcome, not pixel perfect.
Placing the header views exactly how I want, but not using any Android placement 'methodology' at all, but instead getX() and setX() later inside the adapter (using .post() so I ensure the position is accurate after inflation) and STILL the same wrong placement.
What am I missing? Shouldn't a RecyclerView inflating children that span the whole width when I specify they should match_parent? I tried debugging the X values for header and view holders, THEY'RE THE SAME but my eyes see different things. I delayed it for some milliseconds but this didn't change a thing.
So the problem turned out that whatever method I used, if the TextViews widths were wrap_content it'll always fit the word inside it. The solution was setting the width to 0dp and let the parent ViewGroup balance everything evenly. In my case I used a TableLayout.
Is there a way to dynamically set the ViewPager to wrap the child image just nice without leaving any space in between the height of the view pager and the top and bottom of the image?
I tried using the solution of https://gist.github.com/egslava/589b82a6add9c816a007
But the solution in the link only wraps all the images according to the height of the highest child view. Which makes every other smaller lower images look even flatter.
Is there a way to wrap the images according to each height of the child images? I don't mind the width being cropped off, I'm just more worried about the height. Some of my images fits perfectly without any loose spaces but there are a few which seems too flat in the view pager.
Hope to see your answers soon. Thanks for reading.
If it's white space you want to avoid why not try setting background to transparent.
I have a list view which is rendered each time with a different list of items, with variable height.
What I want is to set all the Views in the list view to the same layout height according to the view with the highest layout_height, when setting it to layout_height="wrap_content" for each View.
Also I would like to apply min and max values for the height.
So if I define min=30dp,max=100dp, and the biggest View is automatically rendered with 70dp
all Views in the ListView should be set to 70dp.
I have no idea how to go about it, expect for calculating in the code the max view height values, and setting them to all views, but this doesn't seem very elegant to me, especially as I need to translate it to DPs in the code.
Any simpler ideas?
Your right what you try to achieve wont be as pretty as the regular way, but it'll work ;) usually you would decide height beforehand and then go with it :)
I need to put a view (a image for example) in a custom point of the interface.
Are there a method to put a view in a exact pixel / virtual pixel (dp) - zone of the screen?
I need that the view is displayed above the other views.
I think to obligatory put a RelativeLayout and inside it all the layouts of the app and then put the view relative to this layout but i need a method more transparent to the future developers be able use it
EDIT:
I forget to say that i need to put the view programmatically and in the run time. I create the interface, make things in my app and then put a image in a concrete zone of the view above the others views for example in the half of the screen or in the top or in the 20% of the screen or ...
You can set margins for layouts and padding for views inside them, and you can specify position relative to edges, or to other views, there. Also you can specify fixed position for layouts by replacing (match_parent/fill_parent or wrap_content) with actual size( Note that you should specify all dimensions in dp or dip)
For instance you have a linear layout and you want an image view to be 20 dp to the right of the left margin you can try something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android::layout_marginLeft="20dp">
<!-- Nest your views here and if you want you can set padding for them
</LinearLayout>
If you want your views to be on a certain part of the screen, like top of the screen/ bottom of the screen etc, you can nest all of them inside a RelativeLayout. This is a nice way to do it, and it will remove any confusion.
Good luck,
Arkde
What about a FrameLayout as in the example I posted here?
You can use AbsoluteLayout, although it's deprecated.