Layout with a ListView - android

I have a Activity with a layout that is a Vertical LinearLayout with a RelativeLayout, ListView, and another RelativeLayout. My problem is if the ListView is longer than the screen, the bottom RelativeLayout will be unreachable. How can I ensure the last RelativeLayout is always at the end of the ListView? Can I make it part of the ListView somehow?

If you want the Bottom RelativeLayout to be fixed use the root element as RelativeLayout and use alignParentBottom = true to bottom RelativeLayout and position ListView below top relative layout and above bottom relativelayout.
if the bottom Relativelayout has to scroll as you scroll listview add it as a footer to the listview.Checkout this on how to add a footer to listview.

i suggest you to use recyclerview instead of ListVIew

Related

Listview scroll with other elements on page

In my layout, I have two items; an ImageView and a ListView, the ImageView appears on top of the ListView in a LinearLayout. The ImageView displays a logo or a profile image while the ListView displays a list of personal / company info.
Now this is my problem, the ListView scrolls on it's own with the ImageView fixed at the top but I want the ImageView to scroll with the ListView so that it is not fixed statically on top.
How do I do this? Is this possible? And if yes can I see an example. Thanks. :)
Edit: I have considered removing the scroll from the ListView and simply just displaying the items without scroll then I can wrap both the ImageView and ListView inside a ScrollView. However I do not know if this is possible or how I can implement it.
Take NestedScrollView as you parent layout and add a LinearLayout as it's child and add your ImageView and listView as child to this linear layout .
<NestedScrollView>
<LinearLayout>
<ImageView/>
<ListView/>
</LinearLayout>
</NestedScrollView>

scrollview fillviewport linearlayout

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/

ListView with relative layout and scrollview

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.

Adding HorizontalScrollview to multiple layout

I want to create a custom list view.So i created a xml with list item and another xml for row item.For row items I have:
I have a Relative Layout.In which i added textview,Linear Layout.In the Linear Layout I added Horizontal Scrollview and in Horizontal Scrollview I added another Linear Layout with dynamic image views.
The problem is that after i added horizontal scrollview i am not able to do onclick.There is no effect of click.
Remove first LinearLayout in which you have added a HorizontalScrollView as it is useless for horizontalScrollView.After removing that add
android:descendantFocusability="blocksDescendants"
to the
RelativeLayout of Row.xml .
This should work

How to add more Items in Scrollview in Android?

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.

Categories

Resources