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.
Related
I want to have a "fixed_space" at the top of screen and a "scrollview" at the bottom of the screen which should be below fixed_space. The rest of the screen is a container "rest_space".
Unfortunately my scrollview has a shorter height(by 100dp which fixed_space has) ,if content is too big/scrollable.
I tried to achieve same with ConstraintLayout and RelativeLayout, but I have got same result.
Any ideas why scrollview has 100dp shorter height, as it should be?
EDIT: Scrollview should take as much space as she needs.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="#+id/fixed_space"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/holo_red_dark" />
<View
android:id="#+id/rest_space"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:color/black" />
<ScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_green_dark"
android:fillViewport="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="START OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nMIDDLE OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\nEND OF SCROLLVIEW" />
</ScrollView>
</LinearLayout>
Try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="#+id/fixed_space"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/holo_red_dark" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/rest_space"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/scrollview"
android:background="#android:color/black" />
<ScrollView
android:id="#+id/scrollview"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_green_dark"
android:fillViewport="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="START OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nMIDDLE OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\nEND OF SCROLLVIEW" />
</ScrollView>
</RelativeLayout>
</LinearLayout>
Ok, I think this should solve your probem:
First, I started by using RelativeLayout. I did it in order to get the fixed_space aligned to the top and the scrollview aligned to the bottom.
Then I changed the View for a LinearLayout and put a TextView within it so I could use wrap_content and this is the tricky part:
When you use ScrollView with wrap_content and a View with the weight stuff, Android can't make the calculations it needs to get the screen drawed because there is no reference. When I put the TextView with wrap_content itself that gives the reference because Android know the size of the text.
You don't have to use the TextView but you will need anything that gives Android that reference.
In this case, the scrollview is going to be stretched, not the LinearLayout. If you want the second to get strached, then I'm afraid you are going to need to set a fixed height to your scrollview.
<?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"
android:orientation="vertical">
<View
android:id="#+id/fixed_space"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:background="#android:color/holo_red_dark" />
<LinearLayout
android:id="#+id/rest_space"
android:layout_below="#+id/fixed_space"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/black">
<TextView
android:text="Test"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollview"
android:layout_below="#id/rest_space"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_green_dark"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="START OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nMIDDLE OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\nEND OF SCROLLVIEW" />
</ScrollView>
</RelativeLayout>
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.
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>
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);
I am displaying a TextView and below that a ListView in one page. My code is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/widget"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:id="#+id/widgetlay"
android:layout_height="fill_parent">
<TextView
android:id="#+id/txt1"
android:text=""
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
</TextView>
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:id="#+id/listlist"
android:layout_height="0dp"
android:layout_weight="1.0">
</ListView>
</RelativeLayout>
Here I am displaying the ListView data dynamically....but in my emulator it is displaying a TextView at the top and then the ListView with scroll...It is not expanding the list and instead it is scrolling with the content which is generated dynamically...Please tell me how to expand the entire ListView....
Thanks in advance
<?xml version="1.0" encoding="utf-8"?>
<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:gravity="center|center_vertical"
android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="status"
android:id="#+id/txtvw1">
</TextView>
<ListView
android:layout_width="fill_parent"
android:id="#+id/listlist"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
</LinearLayout>
<?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" >
<TextView
android:id="#+id/txtvw1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="status" >
</TextView>
<ListView
android:id="#+id/listlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">
</ListView>
</LinearLayout>
You have an error here
<ListView
android:layout_width="fill_parent"
android:id="#+id/listlist" //error here
android:layout_height="fill_parent">
</ListView>
the ListView is filled of the LinearLayout
so that you can't get the TextView.
instand of this
you can layout your view as follows:
<ListView
android:layout_width="match_parent"
android:id="#+id/listlist" //error here
android:layout_height="0"
android:layout_weight="1.0>
android:layout_weight="1.0" //this will make the list view filled with the rest of the screem
Further more
I suggest you use "match_parent" instand of "fill_parent"
this WAS CHANGED in the SDK level 8...
OK, now you use the RelativeLayout install of the LinearLayout
So you should add the relationship with your views in your layout.
You can layout as this:
<RelativeLayout
android:id="#+id/widgetlay"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" >
</TextView>
<ListView
android:id="#+id/listlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/txt1" />
android:layout_below="#id/txt"----Indicate the relationship with the layout
The RelativeLayout does not have the attr "orientation" and "layout_weight". So I don't suggest you to use this layout, It can't be fixed with the screen height in that way.
The good layout is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/txtvw1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="status" >
</TextView>
<ListView
android:id="#+id/listlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" />
Further more, what do you want to layout your views?
This is a part of my work. List view will appear in the middle of your screen and what ever u need at the top, put it in place of header() and things that u need in bottom of the screen , put it in place of footer(). U can use relative layout instead of the linear layout
Hope this helps.
<?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"
>
<RelativeLayout android:layout_width="match_parent" android:layout_alignParentTop="true"
android:layout_height="wrap_content" android:id="#+id/layout_header">
<include layout="#layout/header"/>
</RelativeLayout>
<LinearLayout android:layout_width="match_parent" android:gravity="center" android:orientation="horizontal" android:weightSum="1"
android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:id="#+id/layout_footer">
<include layout="#layout/footer" />
</LinearLayout>
<ListView android:id="#android:id/list" android:layout_below="#id/layout_header" android:layout_above="#id/layout_footer"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:visibility="visible" />
<!-- <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/> -->
</RelativeLayout>
I don't know what is meaning of expanding meaning here, but listView in scroll view dont behave normally. To resolve this issue you need to implement list view outside of scrollview.
I don't quite understand what you mean, but if you want to have the textView scroll with the content of the listView, you need to add it as a header in your listView.
Moreover, it is not a good idea to put a listview in a scrollview, the listview being scrollable, it messes with the scrollview mechanism.
You can NEVER ever place a listview in the SCrollView.It wont behave properly.Instead of it try using LinearLayout TextView ListView < /Linearlayout>