Linearlayout With Weight-attributes On Children Inside A Scrollview
Solution 1:
As I said in my comments, I don't know if what you're trying to do is possible at the xml level. One option would be to modify your current layout and add a root FrameLayout
to which you'll, initially, add the ScrollView
and above it, the LinearLayout
. In this position the ImageView
will behave as you want as the user didn't modify the layout. When you need to show more in your layout you'll detach the LinearLayout
from the view hierarchy(with removeView
) and attach it to the ScrollView
(with addView
). You'll reverse this when the user goes back to the initial layout.
This will make the ImageView
to have different heights when making the views switch so you'd want to get the height of the ImageView
and re set it when doing the switch. To get the height, you could do it in a listener or using the post
method in onCreate
(as the views haven't been laid out yet at that moment). Also, remember that the user could turn the phone, I don't know if this will affect your layout, but take it consideration.
Solution 2:
Firstly i tried running your code and it didn't cause any issue for me. The scrollView did not show up although the image was scaled to a ScreenHeight-160dp height which i expected because you have used weight 1 for this imageview.
I would suggest that you remove the weight and give height as wrapcontent. In that case the Imageview will just enclose the Image. When it becomes bigger in size, automatically scrollview come into use if the total heights of all screen contents is more than the screenheight.
Post a Comment for "Linearlayout With Weight-attributes On Children Inside A Scrollview"