I have a child layout within a scrollview that contains many objects that move around depending on their layout size (having attributes like centerVertical=true). The problem is that the scrollview won't begin scrolling until the layout becomes as small as possible, which makes many of these objects overlap each other. I'm trying to correct this by setting the child height to a custom value, however the entire layout becomes jumbled then. I have fillviewport=true, I'm just trying to find a way to control the height of the child inside the scrollview because it is deciding to make it too small by itself. Thanks!
Related
I need to implement a View, containing a RelativeLayout.
The Width and Height of the parent should be absolute values.
The child's Width and Height are either set to WRAP_CONTENT or an absolute value, but never to MATCH_PARENT.
The child may be larger than the parent. If this is the case, only the part of the RelativeLayout which fitted in the parent View, should be visible, as in the picture below.
Also, the RelativeLayout should be able to be moved and therefor change the visible part in the parent View. Unfortunately, Android doesn't let me do this. The child is allways clipped down to fit inside the parent.
I stumbled across ScrollView and HorizontalScrollView allready, but they allow the user to scroll around and that's not what I want him to be able to. There's just this too big RelativeLayout of which I want to show the user a just a part of.
Everything is added to the screen programmatically, without XML.
Is it possible? Maybe I haven't seen some obvios possibilities with ScrollView?
As you suggest you can use a ScrollView and disable scrolling in this view.
To do this read this answer:
Disable ScrollView Programmatically?
;)
Try to set layout's clipChildren:false
http://developer.android.com/reference/android/view/ViewGroup.html#attr_android:clipChildren
I have solved a weird issue, and I would like to know why it happens.
My application creates screens with FrameLayout as the root element. For Simplicity, let´s say I have a Framelayout with some scrolling elements inside, for example a ScrollView with a TextView, and a GridView.
These child elements are positioned with LayoutParams so I assign them a Width, a Height, and a Margin Left / Margin Top. The usual case is their sizes do NOT match the parent, that is, they are floating inside the parent FrameLayout.
For non-scrolling elements, everything is cool.
But for scrolling elements, when scrolling, I can see all kinds of leftovers OUTSIDE the child bounds. Inside the bounds the scrolling is perfect, but the elements are not clipped properly.
I did a lot of tests, played with setClipChildren / setClipToBounds, changed the root element from FrameLayout to RelativeLayout, etc etc, without success.
I only succeeded when I wrapped the scrolling elements inside another Framelayout/RelativeLayout without any margins, and then assigned the scrolling elements MATCH_PARENT/MATCH PARENT.
The scroll is perfect now, clipping is properly done, but I have added another level of complexity to the layout.
Why does this happen?
Let me explain the scenario that I want to achieve:-
Consider the below as the Layout I have inside a Parent_Linearlayout:
[Linear Layout] (Fill_Parent, Wrap_Content)
[ScrollView]
Activity's setContentView is set to the Parent_Linearlayout
In the application, when a condition is met, I want the Scrollview to be removed from the screen and instead put another View in its place.
I've been able to do this, & when I remove the ScrollView, I'm applying translate Animation to it so that it seems as if the View has gone to the top -before removing it.
But when the animation occurs, the ScrollView translates OVER the Linear layout present above it.
How do I restrict it, so that the scrollview does not go over the linear layout, but disappears at the base of the Linearlayout. I want the linearlayout to always stay visible..
I've been trying to do this from quite some time, but I've not been able to get desired results..
Could someone kindly help me out here??
I don't quite understand your description of your layout, but the Android view system is drawn based on the ordering of the views in the hierarchy. Views added later to a parent are drawn after those added earlier. So if you always want the LinearLayout to be drawn on top of the ScrollView if/when they overlap, then declare or add the ScrollView object to its parent before the LinearLayout object.
In thinking more about this, I suppose the ordering here is important because you want the ScrollView to be placed below the LinearLayout in the parent of both of these views. Putting the ScrollView first (and thus having it painted first) would then put it above the other LinearLayout, which isn't what you want.
There are various ways to achieve what you want. For example, you could use a RelativeLayout as the parent of the views, then the ordering is not important.
Alternatively, you could place the ScrollView inside another LinearLayout (and that LinearLayout would be the second child of the overall parent layout). Then when you animate the ScrollView, it would be clipped by its immediate parent, which I believe would give you the effect you're looking for (make sure that setClipChildren() is set to true on this new intermediate LinearLayout, which it is by default, otherwise it won't clip the ScrollView as it animates out of it). Note that this approach would necessitate different animation values, since you are now animating the view outside of its parent (the new LinearLayout).
I am generating a custom View that contains a number of drawables that are added to the View dynamically. This means the View's size could be anything, and is likely to stretch off the screen. Where it does stretch off the screen I want scrolling to be enabled.
So far I have tried:
adding the custom view directly to my Activity - this displays the drawables ok, but with no scrolling
adding the custom view as a child to a ScrollView and setting the ScrollView as the content in the Activity - this doesn't display anything.
How do I generate a custom view of arbitrary size, display it and have scrolling where it is too big for the screen?
Adding it to a ScrollView should be fine. Remember:
A ScrollView is a FrameLayout, meaning
you should place one child in it
containing the entire contents to
scroll; this child may itself be a
layout manager with a complex
hierarchy of objects. A child that is
often used is a LinearLayout in a
vertical orientation, presenting a
vertical array of top-level items that
the user can scroll through.
To make sure your "custom view" is working fine, first try to add a LinearLayout to the ScrollView and then add drawables to the LinearLayout.
I have a very simple layout with two side by side textviews. Both have the same parent layout that fills the screen horizontally.
I need them to have a visible space between them so that they are visually seperated when both have text. I also need the left textview to take up about 2/3 the screen width and let the other have the rest.
This is fairly easy to do with LinearLayout and a few margin settings, but if either one of the views has no text, I need the other one to fill the entire width.
I'm not quite sure how to have the layout do that without setting the empty view's visibility to GONE in code. Is there any good, efficient way to do all of these things at once? Feel free to use any layout you wish to make it work.
have you tried this using a relative layout? there is a property for layout_alignWithParentIfMissing that might give you what you need...