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.?
A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it.
Only one view can be included in a ScrollView .
NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.
In the practical on scrolling views, you use ScrollView to scroll a View or ViewGroup . ScrollView is easy to use, but it's not recommended for long, scrollable lists. RecyclerView is a subclass of ViewGroup and is a more resource-efficient way to display scrollable lists.
<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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With