This question already has answers here:
ListView inside ScrollView is not scrolling on Android
(27 answers)
Closed 6 years ago.
I work on an application that contain an XML file with some ListView I'd like to make them to scroll inside a LinearLayout, so i've done it with ScrollView but it's not possible, i need your helps, thanks in advance, here is my source code :
XML-FILE :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ListViewCatalogueRDV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/TextViewDimancheCatalogueRDV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/TextViewDimancheCatalogueRDV"
android:textSize="30sp" />
<ListView
android:id="#+id/ListViewDimancheCatalogueRDV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/TextViewLundiCatalogueRDV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/TextViewLundiCatalogueRDV"
android:textSize="30sp" />
<ListView
android:id="#+id/ListViewLundiCatalogueRDV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</ListView>
</LinearLayout>
</LinearLayout>
I would suggest you to use ExpandableHeightListView
If you dont want to use ExpandableHeightListView than you can try following
Never put listview in scroll view. Listview itself is scrollable.
check https://developer.android.com/reference/android/widget/ListView.html
A view that shows items in a vertically scrolling list
you need to use weightSum, check below layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:fadingEdge="none"
android:fillViewport="true"
android:isScrollContainer="true"
android:scrollbars="none" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ListViewCatalogueRDV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical"
android:weightSum="3" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/TextViewDimancheCatalogueRDV1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="TextViewDimancheCatalogueRDV"
android:textSize="30sp" />
<ListView
android:id="#+id/ListViewDimancheCatalogueRDV1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</ListView >
</LinearLayout >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/TextViewLundiCatalogueRDV2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="TextViewLundiCatalogueRDV"
android:textSize="30sp" />
<ListView
android:id="#+id/ListViewLundiCatalogueRDV2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</ListView >
</LinearLayout >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/TextViewDimancheCatalogueRDV3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="TextViewDimancheCatalogueRDV"
android:textSize="30sp" />
<ListView
android:id="#+id/ListViewDimancheCatalogueRDV3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</ListView >
</LinearLayout >
</LinearLayout >
</ScrollView >
In the very first Linear Layout set android:orientation="vertical" android:scrollbars="vertical"
Finally i've found a solution, thanks for all your efforts (^_^), here is a solution : stackoverflow.com/questions/6210895/
Related
I want to apply background image on Relativelayout Under ScrollView.
The Image Appear on XML View but Not Appear on Actual device.
I have added ImageView on Ralativelayout
>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:id="#+id/parentView"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/cloudbg"
/>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:id="#+id/vo"
android:layout_below="#id/relativeLayout"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="XYZ"
/>
<TextView
android:layout_width="wrap_content"
android:layout_marginLeft="25dp"
android:layout_height="wrap_content"
android:id="#+id/textvo"
android:text="Voter Number"
/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
Thanks
can try this way:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/cloudbg">
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:id="#+id/vo"
android:layout_below="#id/relativeLayout"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="XYZ"
/>
<TextView
android:layout_width="wrap_content"
android:layout_marginLeft="25dp"
android:layout_height="wrap_content"
android:id="#+id/textvo"
android:text="Voter Number"
/>
</LinearLayout>
</ScrollView>
Use android:background="#drawable/background_image" attribute in Relative or Linear Layout tag.
Set background for scrollview
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/ic_launcher" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
I'm not sure exactly why this is happening but I've specified android:layout_alignParentBottom="true" and android:gravity="bottom" in my (Android) xml layout however the item (HorizontalScrollView containing carousel1) still appears at the top of the layout.
I'm not sure exactly what is wrong in this instance.
Thanks in advance.
Screenshot:
http://i.stack.imgur.com/wefnn.png
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="00dp"
android:layout_marginTop="0dp"
android:background="#drawable/background_faded"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:background="#000000"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="20dip" >
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/imageView1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="0dp"
android:background="#drawable/main_header_selector"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:scrollbars="none" >
<LinearLayout
android:id="#+id/carousel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
</LinearLayout>
I changed the parent LinearLayout to RelativeLayout and in the linearlayout of ScrollView i removed android:layout_alignParentBottom="true" and just added android:layout_gravity="bottom". I hope this will help you. Here is the xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="00dp"
android:layout_marginTop="0dp"
android:background="#drawable/background_faded"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:background="#000000"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="20dip" >
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/imageView1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_marginTop="0dp"
android:background="#drawable/main_header_selector"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:scrollbars="none" >
<LinearLayout
android:id="#+id/carousel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
In your HorizontalScrollView, don't use layout_alignParentBottom, use android:layout_gravity="bottom". See LinearLayout.LayoutParams reference guide.
LinearLayout uses layout_gravity for its children, RelativeLayout uses layout_alignX where X is top, bottom, etc. If you wanted, you could keep it as layout_alignParentBottom but the parent of your HorizontalScrollView would need to be a RelativeLayout. Either solution should accomplish the same effect.
Try this layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="00dp"
android:layout_marginTop="0dp"
android:background="#drawable/background_faded"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="#000000"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="20dip" >
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="0dp"
android:background="#drawable/background_faded"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:scrollbars="none" >
<LinearLayout
android:id="#+id/carousel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
i want to have like this design.header when listview and image bellow in this listview.i wrote xml code.also i used scrollview but my listview's height des not change when i adaptered my array.i can show only first item in listview.
in my option problem is xml file
this is a source xml file
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/ic_launcher"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#ff0000" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/geocell" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/relativeLayout1"
android:orientation="vertical" >
<ListView
android:id="#+id/menu_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/relativeLayout2"
android:orientation="horizontal" >
<ImageView
android:id="#+id/popapshow"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/geocell" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
Remove LinearLayout from the root and add ScrollView
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
Try this one
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<RelativeLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
I want to put a ListView at the top of my activity, and something else on the bottom without the ListView "swallowing" the widgets on the bottom? I tried this (with the "something else" being a RelativeLayout with a single button in it), but it doesn't work.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" >
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Button" />
</RelativeLayout>
</LinearLayout>
I looked for some hints here, which is very useful, but doesn't say anything about ListViews. I can place widgets above a ListView without problem, but not below.
Use a RelativeLayout as the root layout then position the ListView with layout_above and the Button with layout_alignParentBottom:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button" >
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Button" />
</RelativeLayout>
I'm sure this is already answered several times on SO...
Change your layout like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="bottom" >
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Button" />
</RelativeLayout>
</LinearLayout>
I'm trying to create a android layout like:
[####EditText###][Button]
[####listview#####]
For that i'm using weight, but the following xml is giving me something very strang like:
[editText][button][ListView]
Someone know why?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/background"
android:weightSum="10"
>
<EditText android:id="#+id/nova_lista"
android:inputType="text"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="9"
android:hint="#string/new_list_hint">
</EditText>
<Button android:id="#+id/nova_lista_botao"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="#string/new_list"/>
<ListView
android:id="#+id/list_of_lists"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
You are using android:orientation="vertical"
and you are specifying android:layout_width equal to 0dp.
For vertical layout layout_height should be 0 dp and for Horizontal layout layout_width should be 0 dp if you are using weight in LinearLayout.
Put EditText and Button in separate Horizontal Layout. Use below code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/background"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="10"
>
<EditText android:id="#+id/nova_lista"
android:inputType="text"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="9"
android:hint="#string/new_list_hint">
</EditText>
<Button android:id="#+id/nova_lista_botao"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="#string/new_list"/>
</LinearLayout>
<ListView
android:id="#+id/list_of_lists"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Maybe this is what you are looking for:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#ffffff" >
<EditText
android:id="#+id/nova_lista"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_toLeftOf="#id/nova_lista_botao"
android:inputType="text"
android:hint="something">
</EditText>
<Button
android:id="#+id/nova_lista_botao"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:text="Hello"/>
<ListView
android:id="#+id/list_of_lists"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/nova_lista" >
</ListView>
</RelativeLayout>
Hope that helps.
1.Set your main layout is RelativeLayout
2.Create LinarLayout and move EditText and Button to LinerLayout
3.Set LinerLayout is "#+id/top_layout" and set listview is
android:layout_below="#+id/top_layout"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/background"
android:weightSum="10" >
<LinearLayout
android:id="#+id/top_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/nova_lista"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:hint="#string/new_list_hint"
android:inputType="text" >
</EditText>
<Button
android:id="#+id/nova_lista_botao"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/new_list" />
</LinearLayout>
<ListView
android:id="#+id/list_of_lists"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/top_layout" >
</ListView>
</RelativeLayout>