How can I create a View, which allows larger children? - android

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

Related

Place a view to the bottom of a relative layout with height wrap_content

So I wanted to place a view at the bottom of a relative layout which has height wrap_content.
Did not work at all and I remembered why.... (straight from the doc)
Note that you cannot have a circular dependency between the size of the RelativeLayout and the position of its children. For example, you cannot have a RelativeLayout whose height is set to WRAP_CONTENT and a child set to ALIGN_PARENT_BOTTOM.
It seems like a very simple thing to want to do. Is there a way to hack this and make it work if there is no other view we can bottom align?
I am hoping there is a standard "hack" before actually presenting a specific non-working example which I have tried with LinearLayout and FrameLayout but could not get the end result I was looking for.
First of all, Put your code first. From your scenario, It looks like you have declared android:layout_below somewhere that may cause circular dependencies.

Set child height dynamically in scrollview

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!

How to scroll only the widgets(Content) but not the background in android

I defined ScrollView and I put inside some buttons. I have two problems:
If I have a little bit buttons then the background is too small
and does not cover whole screen.
I want to just move buttons but not the the background when I
scroll.
Thank you
Put the scrollview inside a linear layout or a framelayout and add the background to the outer layouts. So when only the items in your scroll view will move.
Also try adding background directly to the scrollview and not to its child elements, that might work without needing to add a extra out layout like I mentioned above.
For your first question, what is the scrollview's layout_width and layout_height values? I'm guessing it's wrap_content. Try changing it to match_parent or fill_parent.
For your second question, blessenm's reply works for me.

ExpandableListView affecting the size of Scrollview when collapsing and expanding

Let me try to explain what I want to achieve. Currently, I have a ScrollView as the main view for my layout and a linearLayout within that to place all of my content into.
In my LinearLayout, I have a bunch of textviews and a gallery, which extends out of the screen, so the user can scroll to see everything. It works.
Now, I want to add an expandableListView to the bottom of all that content, which is still in the linearLayout. The problem is when you expand the list view groups it doesn't affect the ScrollView. I had envisaged that when you expand a group it would make the linearLayout bigger, which in turn makes the scrollview bigger.
Is what I'm thinking achievable?
EDIT:
Ok I think the situation is that listViews are normally placed in a layout by themselves and have scrollviews already enabled. You just set it to fill_parent and it works fine. However, in my case, I'll need the expandableListView to display all content without scrolling, because my ScrollView will deal with that. I don't even think it possible?
It's difficult to answert without seeing your layout xml, but I think that if you set the android:layout_height of the linear layout and expandableListView to wrap_content, the first scrollView must scroll the whole view.
have you tried putting your expandable list into another linear layout and than put it in the scroll views default linear layout?

How to restrict bounds for Translate Animation for a view in Android?

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

Categories

Resources