basically I have layout with some views (TextView, editText and buttons) that almost filling the screen and the bottom of these views I have ListVew element.
I'm populating this list on run time.The problem I have that the scrolling of the listView is not working.I tried to have scrolling bar on the whole layout and it did not work.
What is the best way to have listview at the end of your layout?
regards,
red sea
Never put listview,mapview,Webview in scrollview because these views already have scrolling.
I think other view like textview,imageview put in RelativeLayout and this Relativelayout put in scrollview.and complete the tag of scrollview </ScrollView> .now You should add listview below scrollView.
Like.
<ScrollView android:id="#+id/scroll" ...>
<RelativeLayout...>
<TextView... />
<TextView... />
<ImageView... />
</RelativeLayout>
</ScrollView>
<ListView android:layout_below="#+id/#+id/scroll"... />
Related
I have the following layout
<LinearLayout
android:orientation="vertical"
...
/>
<include .../>
<include .../>
<ListView ... />
</LinearLayout>
Naturally the content of the ListView scrolls. But what I want is for the entire LinearLayout to scroll concurrently with the ListView, appropriately of course: i.e. both should scroll until only the ListView is on screen. I already tried wrapping the LinearLayout with a ScrollView. That's not working
You can inflate a custom view using layout inflater then use this:
myList.addFooterView(myFooter);//for header
myList.addHeaderView(myHeader);//for footer
It's an old and old question.Listview locates inside the scrollview beside a linearlayout.
Maybe there are tow solutions:
1.give up using it.
2.confirm the height of listview or make the height dynamic.While,when I code in this way,I find the focus is always on the bottom of the listview.And request.setFocus() donen't work....
How to deal with it??
You should not place the list view inside a ScrollView. If you want to show something above or below the list and want to scroll them together the list, you just need to use header or footer views.
An example:
The main screen content:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
The footer view (list_footer.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"><!-- the footer content -->
</LinearLayout>
Adding footer in code: You should do it before setting an adapter for the list
ListView listView = (ListView) view.findViewById(R.id.main_list);
View footer = LayoutInflater.from(getActivity()).inflate(R.layout.list_footer, listView, false);
listView.addFooterView(footer);
listView.setAdapter(yourAdapter);
A ScrollView can only hold a child. If that Linearout is really necessary(usually it's just a holder), you should do this:
<ScrollView>
<LinearLayout>
<ListView>
<!-- Blahblah -->
</ListView>
<LinearLayout>
<!-- Blahblah -->
</LinearLayout>
</LinearLayout>
</ScrollView>
So I've got this layout scenario that I havent found any desirable solution for. I've made a paint of it, i hope it's understandable.
Right now my ListView is always above the LinearLayout at the bottom. When the ListView has few items, the TextView is just below and it looks fine. However when it has many items, it crushes the TextView in between, which should always be there no matter what, between the LW and bottom container.
Could anyone give me a xml example that achieves just this?
You can wrap the ListView inside a LinearLayout and set weights to this Linearlayout, the TextView and the bottom LinearLayout. (You have to wrap the ListView inside a LinearLayout because you can't apply weights to a ListView).
If I don't missundestand you, You try to create a ListView such as wrap_content? and the TextView is always below the ListView? If i'm not wrong, so, this is what you need:
<LinearLayout // Your list view and TextView in a same linear layout
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="400dp" // With this specific height, your TextView will
// always in this range!
android:orientation="vertical" >
<ListView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.1" >
</ListView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="91dp"
//layout_gravity = "right"?? I'm not sure, you should make it right alignment
/>
</LinearLayout>
<LinearLayout /> // This is your linear layout at the Bottom, 2 Lineary layout is
// putted in a Relative layout
The layout above give you a ListView at the top, and the TextView is below, the LinearLayout at the Bottom. Try it out!!
I have a ListView and TextView. They are both in a LinearLayout. And this LinearLayout is inside the ScrollView. So it looks like this:
Linearlayout
ScrollView
linearlayout
ListView
TextView
Linearlayout
ScrollView
linearlayout
But you can't scroll through it.
It just displays the ListView. And the ListView is cropped for some reason.
Is this normal? If not then how to solve this?
use following xml code.If i am right you don't need Listview.you can do this with only text view. Here is code for Scrolling Listview.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:id="#+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="30px" >
</TextView>
</LinearLayout>
Yup, this is a problem because list-view is already a scroll-view. Basically, when you encapsulate a scroll-view inside another scroll-view, android has no way to know which scroll-view the user wants to scroll. Generally, the bottom-most layer is scrolled. iOS still gets you through this problem in certain cases but android never does. You'll get weird scrolling characteristics. You can put a horizontal scroll-view inside a vertical one and that'll work fine. So I'd recommend changing your design in a way that you do not use the ScrollView
I've faced same problem.
Just change your ScrollView tag into HorizontalScrollView inside your xml and you're done.
I have a Layout which contains a ListView some buttons below it.
What I want is for the buttons to be fixed to the bottom of the screen.
When the ListView has several items (more than what fits the screen) the code is working properly and the buttons appear in the bottom of the screen.
However, when the ListView is empty or does not require scrolling, the buttons are coming up the screen (they are not staying fixed in the bottom).
Here's the layout (some details omitted but I can add them if necessary):
<LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView />
<ListView
android:width="fill_parent"
android:height="wrap_parent"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|bottom"
android:orientation="horizontal"
android:layout_weight="0" />
<Button
android:layout_weight="1" />
<Button
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
I expected setting the "gravity" of the second LinearLayout to "bottom" to make the buttons fixed to the bottom of the screen, but it's not working in the mentioned case.
Any ideas?
Thanks.
You have the layout_height of your top LinearLayout set to wrap_content. This means that it will shrink as its contents shrink. Try setting it to fill_parent instead. Or, give it a layout_weight of 1.
One of the options is to create TextView which will be shown instead of listview, when it is empty.
You do it with listView.setEmptyView(emptyView)
Then set layout_weight of this TextView to same weight as your listview. So when listview is empty, its place will be taken by emptyView and buttons will stay fixed at the bottom.
Also set your emptyView to android:gravity="center".
Other option:
In vertical RelativeLayout add to the layout with buttons property android:layout_alignParentBottom="true".
All the stuff with listView put inside LinearLayout and add to it android:layout_above="#+id/buttons_layout".
That's it. Elements inside LinearLayout will take their place depending on weight but whole layout wont go beyond buttons.