Relative Layout inside a ScrollView - Not scrolling - android

I have a relative layout as child of Scrollview. I already tried a bunch of answers in here but the scroll isn't working.
That's my xml file:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:scrollbars="none"
android:fillViewport="true"
android:background="#drawable/home_bg_branco" >
<RelativeLayout
android:id="#+id/relative_categoria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/categoria_placeholder_slider_listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-3dp"
android:contentDescription="#string/home_placeholder_slider"
android:src="#drawable/home_placeholder_slider"
android:visibility="visible" />
<ImageSwitcher
android:id="#+id/home_imageswitcher_slider_listview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_alignBottom="#id/categoria_placeholder_slider_listview"
android:layout_alignLeft="#id/categoria_placeholder_slider_listview"
android:layout_alignRight="#id/categoria_placeholder_slider_listview"
android:layout_alignTop="#id/categoria_placeholder_slider_listview"
android:scaleType="fitXY" />
<ListView
android:id="#+id/listViewCategoria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/home_imageswitcher_slider_listview"
tools:ignore="NestedScrolling" >
</ListView>
<ImageView
android:id="#+id/categoria_cores_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/categoria_placeholder_slider_listview"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:contentDescription="#string/img_cores"
android:src="#drawable/img_cores" />
<ImageView
android:id="#+id/categoria_destaque_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignStart="#id/categoria_placeholder_slider_listview"
android:contentDescription="#string/img_destaques"
android:src="#drawable/img_destaques" />
</RelativeLayout>
</ScrollView>
Another thing: i disabled the listview scroll to avoid conflicts.
Thanks in advance!

You should change layout_height of the RelativeLayout to match_parent:
<RelativeLayout
android:id="#+id/relative_categoria"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
Also remove android:fillViewport="true" from ScrollView.
In my project I have several ScrollViews exactly like this, and they work fine:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
UPDATE
One last thing I can propose is to remove ListView from the ScrollView as it can interfere with layout and scrolling.

Add this line to your onCreate()
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE|WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

Related

Android ListView inside ScrollView not proper

I am sorry, I am new to android xml part. I am setting my listview which is inside scroll view to full screen but its frame is still small. How to resolve it? I have already set both width and height to "match_parent". Can someone help?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.stacktips.speechtotext.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="#layout/row" >
</ListView>
</ScrollView>
<LinearLayout
android:id="#+id/btnSpeakContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#f5f5f5"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="20dp">
<ImageButton
android:id="#+id/btnSpeak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:padding="16dp"
android:scaleType="fitCenter"
android:src="#mipmap/ic_microphone_2" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/btnSpeak"
android:layout_margin="10dp"
android:text="#string/hint" />
</LinearLayout>
</RelativeLayout>
Putting the ListView inside a ScrollView means the ListView will not go to its full height. Take out the ScrollView surrounding the ListView and this should work for you :) ListView itself is scrollable.

ListView not scrolling for Xamarin.Android app

I've placed a fragment tag on my page for a google map and a listview surrounded by a linear layout tag underneath the map. Does anyone know why my list view isn't scrolling. I set my listview fastscrollenabled setting to true and it still doen't scroll.
var locationService = new LocationService(_geoCoder);
listView.Adapter = new ListOfLocationAdapter(this, locationService.GetLatLongOfAddresses());
this.listView.FastScrollEnabled = true;
Here is the XAML I use for the layout.
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="2"
android:columnCount="1">
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="300dp"
class="com.google.android.gms.maps.MapFragment" />
<LinearLayout
android:id="#+id/linearLayout1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/List"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:cacheColorHint="#FFDAFF7F"/>
</LinearLayout>
</GridLayout>
Here is the listadapter code:
<?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="wrap_content"
android:minHeight="50dp"
android:orientation="vertical"
android:background="#ffffff">
<LinearLayout
android:id="#+id/Text"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="vertical">
<TextView
android:id="#+id/CustomerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="20dip"
android:textStyle="italic"
android:paddingLeft="10dip" />
<TextView
android:id="#+id/Address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dip"
android:textColor="#000000"
android:paddingLeft="10dip" />
</LinearLayout>
</RelativeLayout>
I tried removing the relativelayout tag, but that didn't do anything for me.
Set weight to your listview & set height to 0dp. This will make it auto-fill any remaining space, causing the internal items of the listview to scroll.
<ListView
android:id="#+id/List"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:cacheColorHint="#FFDAFF7F" />
When I move the linearlayout around both the fragment and listview the scrolling starts working. For some reason the linear layout was showing off of the bottom of the android layout making it look like it wasn't scrolling until I added more records.
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="2"
android:columnCount="1">
<LinearLayout
android:id="#+id/linearLayout1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="300dp"
class="com.google.android.gms.maps.MapFragment" />
<ListView
android:id="#+id/List"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:cacheColorHint="#FFDAFF7F" />
</LinearLayout>
</GridLayout>
I had the same problem. I just set layout_height of my ListView to match_parent value. This solved my problem.

Two ListView in ScrollView

I have put two listview in scrollview but i have a problem, when i put item in the first listview the second listview will be scrollable. I want that the whole area will be scrollable and not scrollview, How i do? the first scrollview is listViewEventiAggiunti the second listViewEventi.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="true">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="#+id/activity_lista__eventi"
android:paddingBottom="#dimen/padBottom"
android:paddingLeft="#dimen/padLeft"
android:paddingRight="#dimen/padRight"
android:paddingTop="#dimen/padTop"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context="com.example.fra87.eudroid.activity_class.Lista_Eventi">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical">
<SearchView
android:layout_width="match_parent"
android:layout_height="50dp"
android:queryHint="Evento"
android:id="#+id/cercaEvento"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:id="#+id/linearLayoutEventi">
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Nome Evento"
android:textSize="22dip"
android:id="#+id/editText_nome_evento_composto"/>
<ListView
android:id="#+id/listViewEventiAggiunti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp" />
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:id="#+id/separatore_liste"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#android:color/darker_gray"/>
<ListView
android:id="#+id/listViewEventi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/cercaEvento"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
I want scroll entire area, i don't want scroll on listview, when i put item in listview the area increases and i scroll entire area is possible?
Ok. Since your minimum SDK version is 16, you have 2 solution for your problem.
First is use this library:
https://github.com/PaoloRotolo/ExpandableHeightListView
This library makes you able to expand your ListViews to full height and then only your ScrollView will be scrollable.
Second solution is to use NestedScrollView instead of ScrollView and then use RecyclerView instead of ListView. Then you should only disable nestedScrolling for your RecyclerView.
Both solutions will give you your desire behavior.
You can use multiple type item for listview and simplified your layout to become like this
<?xml version="1.0" encoding="utf-8"?><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_lista__eventi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/padBottom"
android:paddingLeft="#dimen/padLeft"
android:paddingRight="#dimen/padRight"
android:paddingTop="#dimen/padTop"
tools:context="com.example.fra87.eudroid.activity_class.Lista_Eventi"
>
<SearchView
android:id="#+id/cercaEvento"
android:layout_width="match_parent"
android:layout_height="50dp"
android:queryHint="Evento"
/>
<EditText
android:id="#+id/editText_nome_evento_composto"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/cercaEvento"
android:hint="Nome Evento"
android:textSize="22dip"
/>
<View
android:id="#+id/separatore_liste"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_below="#+id/editText_nome_evento_composto"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray"
/>
<ListView
android:id="#+id/listViewEventi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/separatore_liste"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
/>
</RelativeLayout>

Android listView center position in RelativeLayout

i have an RelativeLayout and also have listview inside this RelativeLayout. I want my listview would be center position. listivew would start in screen center
this is a my xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ff0000" >
<RelativeLayout
android:id="#+id/LinearLayout1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#000000" >
<ListView
android:id="#+id/menu_content_menulist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:divider="#null" >
</ListView>
</RelativeLayout>
You can use the following in your ListView attributes:
android:layout_centerInParent="true"
FIrst of all you only need one RelativeLayout as parent (If you have no other elements in this xml only ListView would be enough as well).
Below are couple of solutions you can use any of them that suits your requirements
Method 1
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent" >
<ListView
android:id="#+id/menu_content_menulist"
android:layout_width="100dp"
android:layout_height="300dp"
<!-- Used centerInParent property to place the view in Centre of screen -->
android:layout_centerInParent="true">
</ListView>
</RelativeLayout>
Method 2
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
<!-- set the gravity of parent element to center which is applied to its child elements -->
android:gravity="center" >
<ListView
android:id="#+id/menu_content_menulist"
android:layout_width="100dp"
android:layout_height="300dp" >
</ListView>
</RelativeLayout>
Put:
android:gravity="center"
in your main RelativeLayout.
<ListView
android:id="#+id/menu_content_menulist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:divider="#null" >
</ListView>

How to anchor buttons at the bottom of the layout?

I'd like the OK / Cancel buttons to be anchored at the bottom (even when there's more items on the list that can be shown on the screen). Here's what it currently looks like:
The buttons are on the top, not on the bottom.
The layout that contains the buttons:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="true"
android:id="#+id/buttons_layout">
<TableRow>
<Button
android:id="#+id/btnOK"
android:background="#color/pomegranate"
android:text="OK"
android:layout_gravity="fill_horizontal"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnCancel"
android:background="#color/wet_asphalt"
android:text="Cancel"
android:layout_weight="1"
android:layout_gravity="fill_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
The composite layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/options_list"
android:layout_width="fill_parent"
android:layout_height="match_parent">
</ListView>
<include layout="#id/buttons_layout"
android:layout_alignParentBottom="true"
android:layout_height="match_parent"
android:layout_below="#id/options_list"/>
</RelativeLayout>
I followed the guidelines I read on http://developer.android.com/guide/topics/ui/layout/relative.html
I tried this answer - https://stackoverflow.com/a/6285438/168719 - it hasn't helped me.
I suspected that it might not work because the list view doesn't "know" how tall it is, so the button layout doesn't know where to place itself, either. But I ruled it out by setting the ListView height to an arbitrary value like 100dp. The buttons are still superimposed over it.
I fiddled with all the layout attributes, but I can't get it to work.
Apart from the solution, I would also like to know why mine doesn't work...
the layout should be something like this :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView android:id="#+id/options_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/layout_buttons" >
</ListView>
<include android:id="#+id/layout_buttons"
layout="#id/buttons_layout"
android:layout_alignParentBottom="true"
android:layout_height="wrap_parent"
android:layout_width="wrap_content"/>
</RelativeLayout>
you can use tab to do it
you can see this tutorial
Android Tab Layout Tutorial
you could try using it this way
<relativelayout1>
<relativelayout2 specify layout below listview with id="list">
<button1>
<button2>
</relativelayout2>
<listview id="list">
</listview>
</relativelayout1>
so this will ensure no matter how long your list is you always get the buttons below your list. so you can have a scrolling list and a static buttons below the list
try this. Put the include tag inside another RelativeLayout, then be sure ListView is above the new RelativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parentLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/buttonsContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<include
android:id="#+id/buttons"
android:layout_width="wrap_content"
layout="#layout/buttons_layout" />
</RelativeLayout>
<ListView
android:id="#+id/options_list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#id/buttonsContent" >
</ListView>
</RelativeLayout>
Try like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/layout_buttons"
android:orientation="vertical" >
<ListView android:id="#+id/options_list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
<include android:id="#+id/layout_buttons"
layout="#id/buttons_layout"
android:layout_alignParentBottom="true"
android:layout_height="wrap_parent"
android:layout_width="wrap_content"/>
</RelativeLayout>

Categories

Resources