Scrollview doesn't scroll with 2 listview - java

i search lot of topic about scrollview which doesn't scroll but no one can resolve my issue :/
if someone could help me :)
each listview print some people when i do a request from my server
normally when i scroll down of my list the second list appear but it does not
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/selector_for_background_white"
android:orientation="vertical">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/selector_for_background_white"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/layoutScrollResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/selector_for_background_white">
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal">
<com.whask.whask.utils.font.FontTextView
android:id="#+id/text_hot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:background="#android:color/transparent"
android:text="5 HOT"
android:textSize="#dimen/abc_text_size_medium_material"
app:font="Neo-Sans-Std-Medium.otf"/>
</LinearLayout>
<ListView
android:id="#+id/result_whask_listview_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/layout2">
</ListView>
<LinearLayout
android:id="#+id/layout3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/result_whask_listview_view"
android:orientation="horizontal">
<com.whask.whask.utils.font.FontTextView
android:id="#+id/text_not"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:background="#android:color/transparent"
android:text="2 NOT"
android:textSize="#dimen/abc_text_size_medium_material"
app:font="Neo-Sans-Std-Medium.otf"/>
</LinearLayout>
<ListView
android:id="#+id/result_whask_listview_view_no"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/layout3"
android:background="#color/my_whask_white_color">
</ListView>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>

DO NOT use ListView inside ScrollView. ListView itself has a scroll property and you don't have to use another ScrollView to make it scroll. Use a LinearLayout instead.

Listview have own scrolling property ,so dont use within scrollview...
thanks

Related

Scrolling the whole view with a ListView insida a ScrollView

I'm making an app and I can't find any solutions.Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#color/DarkGray"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/BackGroundColor"
android:orientation="horizontal"
android:paddingTop="4dp"
android:paddingBottom="4dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#color/SecondaryTextColor"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#color/SecondaryTextColor"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="#color/BlueGray"
android:nestedScrollingEnabled="false"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/BackGroundColor"
android:padding="4dp"
android:textAlignment="center"
android:textColor="#color/PrimaryTextColor"
android:textSize="22sp" />
<ListView
android:id="#+id/eventsListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
What I'm trying to achive is add CardViews inside my ListView and be able to scroll not just the ListView but the whole view. I tried RecyclerView before but that didn't work for me either.
Here's my idea:
and Scroll the whole thing not just the ListView.
You need to use NestedScrollView.
NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.
Please refer NestedScrollView documentation
Don't forget to add recyclerView.setNestedScrollingEnabled(false); to your RecyclerView.

adView is not visible with wrap content

In the XML layout, everything seems perfect. When I used the emulator or real device, the adView is not visible. I tried to give height to adView like 200 dp. Then the adView is visible. But, when I gave the value of wrap_content for the height of the adView, there is a problem. I used LinearLayout and RelativeLayout but the problem is the same. What should I do for this?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:padding="30dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:text="#string/nav_contact_us_content_explanation" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="email"
android:gravity="center"
android:selectAllOnFocus="false"
android:text="#string/nav_contact_us_content_mail" />
</LinearLayout>
<com.google.android.gms.ads.AdView
android:id="#+id/adview_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"></com.google.android.gms.ads.AdView>
</LinearLayout>
Try to put AdView in FrameLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:padding="30dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:text="#string/nav_contact_us_content_explanation" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="email"
android:gravity="center"
android:selectAllOnFocus="false"
android:text="#string/nav_contact_us_content_mail" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.gms.ads.AdView
android:id="#+id/adview_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"/>
</FrameLayout>
</LinearLayout>
In the case of LinearLayout, as the weight was set to 1, it took the whole screen when the ad was not yet loaded. However, you should see a warning like the following in your logcat here.
W/Ads: Not enough space to show ad. Needs 320x50 dp, but only has 288x495 dp.
In order to fix the problem, you might consider using a RelativeLayout instead of a LinearLayout like the following.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
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/adview"
android:orientation="vertical"
android:padding="30dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:text="Contact us" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="email"
android:gravity="center"
android:selectAllOnFocus="false"
android:text="Email" />
</LinearLayout>
<LinearLayout
android:id="#+id/adview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<com.google.android.gms.ads.AdView
android:id="#+id/adview_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />
</LinearLayout>
</RelativeLayout>
On the other hand, you might also consider setting up a fixed size for the AdView so that it does not hide when the content is not yet loaded. You can get the sizes of different types of ads for different screen sizes here.

Android Margin and Padding aren't working for RecyclerViews inside ScrollViews

When I place a RecyclerView as a child of a ScrollView, marginBottom and paddingBottom doesn't work. Setting these values for the parent LinearLayout doesn't affect anything either. It seems that the ScrollView doesn't scroll to the bottom because the ScrollBar doesn't reach the bottom. How can I fix this bug?
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<!--To avoid scroll view from scrolling to the bottom automatically-->
<View android:layout_width="match_parent" android:id="#+id/focus_view" android:layout_height="0dp" android:focusable="true" android:focusableInTouchMode="true"><requestFocus/></View>
<ScrollView
android:id="#+id/sv_categories_statistics"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="4dp">
<LinearLayout
android:id="#+id/ll_categories_statistics_filters_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp">
<LinearLayout
android:id="#+id/ll_categories_statistics_select_date_fragment_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/border_primary_light"
android:padding="4dp"
android:layout_marginEnd="4dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/border_accent"
android:padding="4dp">
<Spinner
android:id="#+id/spn_categories_statistics_bill_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<com.github.mikephil.charting.charts.PieChart
android:id="#+id/pc_categories_statistics"
android:layout_width="match_parent"
android:layout_height="325dp"
android:layout_margin="4dp"/>
<fragment
android:id="#+id/fgm_categories_statistics_not_enough_data"
class="com.dolinsek.elias.cashcockpit.NotEnoughDataFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
app:text="#string/label_not_enough_data_for_statistic"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="8dp"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_categories_statistics"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
Have you tried clipToPadding
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_categories_statistics"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="50dp"
android:clipToPadding="false"/>

LinearLayout is 'pushed' when ListView is populated

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/buttonLayout"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1">
<Button
android:id="#+id/vehicleButton"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="Refresh"
android:onClick="getVehicles" />
<Button
android:id="#+id/logoutButton"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="Logout"
android:onClick="logout" />
</LinearLayout>
<ListView
android:id="#+id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Hi all, when the above ListView is populated with only a few items, I can still see the buttons, however, when the ListView is populated with more than the screen can display, the buttons seem to be 'pushed' above the UI and are no longer visible, only the scrollable ListView is now visible.
Are there any thoughts on how I can make the buttons appear again on longer lists?
Thanks
Try wrapping the ListView inside of a LinearLayout. You are adding a weight to the buttons to make sure they appear, but then when the ListView renders, it seems to be causing that. Let me know if that helps.
<LinearLayout
android:layout_height="0"
android:layout_width="fill_parent"
android:layout_weight="0"
android:orientation="vertical">
<ListView
android:id="#+id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
For reference, I solved this by using a the following:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/buttonLayout"
android:layout_height="40dp"
android:layout_width="match_parent"
android:orientation="horizontal">
<Button
android:id="#+id/vehicleButton"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="Refresh"
android:onClick="getVehicles" />
<Button
android:id="#+id/mapButton"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="Map" />
<Button
android:id="#+id/logoutButton"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="Logout"
android:onClick="logout" />
</LinearLayout>
<ListView
android:id="#+id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#id/buttonLayout">
</ListView>
</RelativeLayout>
So I used a relative layout and also added the
android:layout_below="#id/buttonLayout to the listview to force it show below the buttonLayout

android: image in icon not showing

I'm trying to place a banner at the top of a listview, one that stays there when the list scrolls down. The layout I currently have actually show what I want in the preview but when I run it in the emulator the only thing that appears is the list.
The XML is:
<?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">
<ImageView android:src="#drawable/edinburghcrest"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="#+id/EdUniCrest" android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"></ImageView>
<TextView android:layout_height="wrap_content" android:id="#+id/banner"
android:text="Hotels Nearby" android:textColor="#FFFFFF"
android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content"
android:layout_alignParentTop="true" android:layout_toRightOf="#+id/EdUniCrest"
android:layout_alignParentRight="true" android:layout_alignBottom="#+id/EdUniCrest"
android:background="#25476C"></TextView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#color/listcolor" android:orientation="vertical" android:layout_marginTop="50dp">
<ListView android:id="#android:id/list" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>
<TextView android:id="#android:id/empty" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="#string/no_lunchs" />
</LinearLayout>
Anyway, I can't see why it isn't working. Does anyone have any idea what it might be?
Thanks.
The RelativeLayout here just makes it confusing. You can achieve this simply with a couple of LinearLayouts. Wrap your banner in a horizontal layout with a height=wrap_content and set you ListView to height=fill_parent. The list will then fill all available space. The List will scroll independently of the rest of the page.
Something like below should work:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:orientation="horizontal" android:id="#+id/bannerBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:src="#drawable/edinburghcrest"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="#+id/EdUniCrest"/>
<TextView android:layout_height="wrap_content" android:id="#+id/banner"
android:text="Hotels Nearby" android:textColor="#FFFFFF"
android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content"
android:background="#25476C"/>
</LinearLayout>
<ListView android:id="#android:id/list" android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView android:id="#android:id/empty" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:text="#string/no_lunchs" />
</LinearLayout>
What if you wrapped your RelativeLayout in a ScrollView, and since a ScrollView can only have one child, put the banner above it?

Categories