My android page has 10 EditText and 10 TextView. but there is no space in my screen in the Graphical Layout. i just added 5 only. im using Scroll layout. how to add additional 5 items in the screen without reducing the items height. Is there any coding here.?
<ScrollView>
<LinearLayout>
<TextView/>..
....
..
</LinearLayout>
</ScrollView>
You can add multiple items inside a LinearLayout. Since ScrollView is scrollable it won't affect the dimensions of the Views inside. You can add as many views as you need without worrying about screen size or View size..
You should add a LinearLayout as the only child inside your ScrollView. Then get a reference to that LinearLayout :
mLayout=(LinearLayout)findViewById(R.id.myLayout);
and then add Views dynamically from code using :
EditText et=new EditText(...);
//....
mLayout.addView(et);
A ScrollView can have only one direct child, so you need to put all the other Views in a Layout, such as LinearLayout and put that layout in ScrollView
Make your ScrollView's height as match_parent and the inner LinearLayout's height as wrap_content. The LinearLayout will stretch according to the number of children inside it and if the height exceeds the height of the ScrollView, the overflow can be seen by scrolling. If the ScrollView and inner Layout both have same height or if ScrollView have larger height than inner Layout, the scrolling won't happen for obvious reason.
Related
As the title says. I'm trying to display extremely complex layout with a full height of the viewport but I need it scrollable because under it there is a simple recyclerview with some items. I already thought about putting everything inside a multi type recyclerview adapter but the logic of the upper layout is so complex that I don't think it's possible.
I tried using NestedScrollView with fillViewport set to true but I'm stuck defining dimensions of this upper layout and recyclerview below it. Everything needs to be inside one layout because scrollview can't have more than one child, but when I put everything in a linearlayout and set the upper layout to match_parent it's showing fullscreen until data loads in the recyclerview below it. Then it's treating this upper layout as if it was wrap_content.
I'm out of ideas how can I do something like this. Preferably best would be to have some sort of ViewGroup which would support scrolling and resize the recyclerview below it as we scroll, but I'm not sure how to do it.
you need to set the layout to something like this:
<NestedScrollView - height:match_parent>
<LinearLayout - height:wrap_content>
<LinearLayout(topview) - height:wrap_content/>
<RecyclerView - height:wrap_content />
</LinearLayout>
</NestedScrollView>
And then you programmatically change the height of the "topview" to equal nestedscrollview.
Is there any way to have a ScrollView with android:fillViewport="true" and a child LinearLayout filling all the view when the content of the LinearLayout is not hight enough?
So far, in a LinearLayout inside a ScrollView we have to use android:layout_height="wrap_content". Can we add something else for filling all ScrollView?
What's the point? LinearLayout content won't stretch to fill ScrollView anyway. If you want to center LinearLayout in (fillViewPorted) ScrollView, use android:gravity="center" in LinearLayout. If you want to use LinearLayout weights to fill screen, don't use ScrollView, as it's height is potentially infinite. If
Set the android:layout_weight of the contents to 1.0. That will force the contents to use the available empty space when it is shorter than the ScrollView. It only works when android:fillViewport=
"true" is set on the scroll view.
Source: http://www.curious-creature.com/2010/08/15/scrollviews-handy-trick/
I am using a scrollview in which i have added 3 relative layout and a list so the stack is like
Scrollview
Relative Layout
Relative Layout
______ ListView
Relative Layout
Now when i am trying to add entries in listview it is now increasing its height. I have set wrap_content for the height field.
Use only listView and add the relativeLayouts as headers/footers.
Fix the height of listview because you are using scrollview
you can scroll and view that list while scrolling content inside listview.
I have a ScrollView that contains a LinearLayout.
In code I add items to the LinearLayout and it nicely expands.
When I remove, in code, all the items from the LinearLayout, the LinearLayout stays the same size, it's empty though.
How do I get the ScrollView to reclaim the height that the LinearLayout used when it had items and shrink back the LinearLayout to use the least height as it is now empty?
I have tried (in C#):
linearLayout.RemoveAllViewsInLayout();
linearLayout.PostInvalidate();
scrollView.PostInvalidate();
Java or C# answers are fine.
I only have Java experience with Android, so I would try using:
linearLayout.requestLayout();
This should cause another layout pass, and assuming your LinearLayout is set to WRAP_CONTENT it will measure all the children and size itself to fit the smallest space that the children occupy (or minHeight if you have that set and it is larger).
This trick seems to work. The result is that the linearlayout ids resized and the scrollview as well:
linearLayout.RemoveAllViewsInLayout();
linearLayout.Visibility = ViewStates.Gone;
scrollView.SmoothScrollTo(0, 0);
linearLayout.Visibility = ViewStates.Visible;
There must be a better way, but this works.
I'm trying to have a ScrollView centered top to bottom within its parent, but I'd also like the ScrollView to be no taller than the height of it's child. The child's height is variable. If there is room, the ScrollView should stretch to be exactly the height of it's child. Any suggestion on how to set up this layout?
Put the ScrollView inside a android:layout_height="match_parent" RelativeLayout.
set the ScrollView to android:layout_centerVertical="true".
Set the ScrollView's height to android:layout_height="wrap_content".
This should get you a centered scrollview that is up to but no taller than the relativelayout that contains it.
Out of curiosity, why do you not want the scrollview set to fill_parent/fillViewport? I would suggest doing that, and simply centering the content of the scrollview instead.