Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to make child view wider than parent in Android Layout

I'm moving a view after an animation completes(to slide out a menu from the left). However, I don't seem to be able to achieve the effect I'm looking for. What I'd like is for the view to extend to the right past the parent's bounds, like this:

What I want

but what's happening is actually this:

Actual Result

The view resets itself to stay within the bounds of the parent. Even if I set an absolute pixel value (by looking at the display's width, or even a randomly large value).

The reason I need to do this is detailed in this SO question about a view's actual position after an animation has completed: TranslateAnimated ImageView not clickable after animation [Android]

any thoughts? Thanks!

like image 562
Joel Martinez Avatar asked Dec 01 '11 21:12

Joel Martinez


2 Answers

So, here is a related question. It explains how to move a view out of the screen.

like image 66
Dalmas Avatar answered Jan 03 '23 14:01

Dalmas


I had same problem and I found the solution. I hope it can be helpful. You need to set fixed width if you want to achieve this effect. To find real width of the view you need to measure it. So full solution is:

view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int height = view.getMeasuredHeight();
int width = view.getMeasuredWidth();
view.setLayoutParams(new LinearLayout.LayoutParams(width, height));

(Use LayoutParams of the type corresponding the type of the parent layout)

like image 43
0neel Avatar answered Jan 03 '23 12:01

0neel