ScrollView not displaying all Contents in Homefragment - android

I am trying to disable scrollview and show up all contents in homepage, However till no luck scroll doesn't show up all the contents.I already tried all questions regarding this but still no luck. I would appreciate if anyone could help me.Thank You :)
Here is fragment_home.xml..
<?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"
android:background="#color/bg">
<ProgressBar
android:id="#+id/progressBar"
style="#style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone" />
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="#+id/ContainerSlider"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_latest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_featured"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>

Did you try adding to scrollview
android:fillportView="true"
You also dont need two recyclerview.. Do one with multiple view types.
With that said you also dont need that scrollview. You only need one recyclerview with multiple viewtypes.

Your layout can be handled well by using EPOXY, a library from airbnb.
Will make your life a lot easier.
https://github.com/airbnb/epoxy

Have you tried using NestedScrollView instead?
The LinearLayout should also have a height of match_parent instead of wrap_content.
Also you should only use weight for views that are children of a LinearLayout so you can remove that for the NestedScrollView.
<NestedScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

Related

Recyclerview in scrollview

This is the code :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey_f2"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rv_achievement_badges"
android:focusableInTouchMode="false"
/>
<LinearLayout
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="25dp"
>
<com.sharesmile.share.views.LBTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hall_of_fame"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textColor="#color/black_64"
android:textSize="20sp"
/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rv_hall_of_fame"
android:focusableInTouchMode="false"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
The issue is rv_hall_of_fame does not show all items.
tried nestedsrollview, viewport, canScrollVertically and setNestedScrollingEnabled and nothing is working. Can you let me know.
You should remove the second recyclerview from the linearlayout. Maybe that is the reason you can't see all items.
EDIT:
I think you should use NestedScrollView. I had the same problem in one of my projects and I changed my code to below which solved my problem.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey_f2"
android:fillViewport="true"
android:focusableInTouchMode="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rv_achievement_badges"/>
<com.sharesmile.share.views.LBTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hall_of_fame"
android:layout_marginTop="10dp"
android:textColor="#color/black_64"
android:textSize="20sp"
android:background="#color/white"
android:paddingLeft="25dp"
android:paddingTop="36dp"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rv_hall_of_fame"
android:background="#color/white"
android:layout_marginBottom="7dp"
android:paddingBottom="30dp"
android:paddingTop="30dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
It's not wise to put a RecyclerView or a ListView inside a ScrollView. Android doesn't know how to handle user events. In addition, in your case, you have two RecyclerView inside that root ScrollView... It's madness both for the Android UI framework and for the user.
A solution could be to only use one RecyclerView that handles the scroll user action, and an Adapter that knows how to render everything you use: achievements badges, the hall of fame label, and the players. So, you'll only need one RecyclerView, and it will work like a charm.

Two RecyclerViews in one layout is not working because one is missing in Android

I am developing an Android app. In my app, I want to use two RecyclerViews in one layout. I used LinearLayout to wrap up RecyclerViews because of this Stack Overflow question (Two RecyclerViews under each other in one layout).
As you can see the answer says, to use LinearLayout and set RecyclerViews height to wrap_content. I followed it. But when I run only one RecyclerView is appear and one is missing.
This is the screenshot:
As you can see, only on RecyclerView is appeared.
This is my XML layout:
<LinearLayout
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:scrollbars="vertical"
android:id="#+id/ai_rc_reviews"
android:layout_width="match_parent"
android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:scrollbars="vertical"
android:id="#+id/ai_rc_reviews_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
</LinearLayout>
I tried this as well. Nothing appears on screen:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:id="#+id/ai_rc_reviews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:background="#color/white"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/ai_rc_reviews_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"/>
</LinearLayout>
</ScrollView>
How can I fix my code to use two RecyclerViews in single layout. Is there any better way to do it?
Try using the layout_weight property instead of wrap_content. Give both RecyclerViews same weight and change height to 0dp.
<LinearLayout
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:scrollbars="vertical"
android:id="#+id/ai_rc_reviews"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:scrollbars="vertical"
android:id="#+id/ai_rc_reviews_2"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
Generally it's not a good idea to have two scroll containers one inside the other if they scroll along the same axis. That behavior will most likely cause confusion with the user. Instead, if you are 100% sure that you need to have two scrolling containers vertically stacked - and please try not to do it if not 100% necessary, you should use fixed heights for each container as it will positively impact overall performance of the created layout.
<ScrollView `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"
android:orientation="vertical"
android:scrollbars="none"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!-- Usual Size -->
<LinearLayout
android:id="#+id/usualSize_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_f5f5f5"
android:layout_marginLeft="#dimen/common_10"
android:layout_marginTop="#dimen/common_10"
android:orientation="vertical"
>
<TextView
android:id="#+id/usualSize_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="size"
android:textSize="#dimen/font_15"
android:textColor="#color/color_999999"
android:layout_marginTop="#dimen/common_16"
android:layout_marginBottom="#dimen/common_10"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/usualSize_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="#dimen/list_height"
/>
</LinearLayout>
<!-- MarkImage -->
<LinearLayout
android:id="#+id/mark_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_f5f5f5"
android:layout_marginLeft="#dimen/common_10"
android:layout_marginTop="#dimen/common_10"
android:orientation="vertical"
>
<TextView
android:id="#+id/mark_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="mark"
android:textColor="#color/color_999999"
android:textSize="#dimen/font_15"
android:layout_marginTop="#dimen/common_16"
android:layout_marginBottom="#dimen/common_10"
/>`
<android.support.v7.widget.RecyclerView
android:id="#+id/mark_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="#dimen/list_height" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Here we should think twice the WRAP_CONTENY ,so we should in the file:build.gradle.
Please update version of a library in gradle file :
compile 'com.android.support:recyclerview-v7:23.2.1'
and higher version.please check your version.
How do I make WRAP_CONTENT work on a RecyclerView
<!-- Usual Size -->
<LinearLayout
android:id="#+id/usualSize_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_f5f5f5"
android:layout_marginLeft="#dimen/common_10"
android:layout_marginTop="#dimen/common_10"
android:orientation="vertical">
<TextView
android:id="#+id/usualSize_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="size"
android:textSize="#dimen/font_15"
android:textColor="#color/color_999999"
android:layout_marginTop="#dimen/common_16"
android:layout_marginBottom="#dimen/common_10"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/usualSize_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="#dimen/list_height"/>
</LinearLayout>
<!-- MarkImage -->
<LinearLayout
android:id="#+id/mark_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_f5f5f5"
android:layout_marginLeft="#dimen/common_10"
android:layout_marginTop="#dimen/common_10"
android:orientation="vertical">
<TextView
android:id="#+id/mark_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="mark"
android:textColor="#color/color_999999"
android:textSize="#dimen/font_15"
android:layout_marginTop="#dimen/common_16"
android:layout_marginBottom="#dimen/common_10"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/mark_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="#dimen/list_height"/>
</LinearLayout>
</LinearLayout>
Here we should think twice the WRAP_CONTENY, so we should in the file:build.gradle.
Please update version of a library in gradle file :
compile com.android.support:recyclerview-v7:23.2.1
and higher version. please check your version.
How do I make WRAP_CONTENT work on a RecyclerView
Just in case someone has two RecyclerViews and other views inside one Srcollview,
if you have problem that the first recyclerview won't scroll up or second one part missing,
if you used LinearLayout to contain these RecyclerViews , try to use relativeLayout instead, which solved my problem.

I have some problems with the XML layouts (android development).

I think I have some problems with a LinearLayout container. I do not know how to fix these problems:
I am a beginner to XML but I think the problem is in the second LinearLayout. I hope someone can help me out.
The code is here below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
**<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
andriod:orientation="horizontal" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>**
<Button
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
</LinearLayout>
The problem I see when reading your xml file is that inside the main LinearLayout you have 3 elements with the properties about the width and height as follows:
android:layout_height="match_parent"
android:layout_width="match_parent"
which means you expect the elements to fill entirely the main LinearLayout. This is not going to work. A linear layout has ordered not overlapping elements (RelativeLayout is there for that). Since the main LinearLayout is supposed to be oriented vertically, I suppose that for these three elements, you need to set the properties to match the whole width of main LinearLayout and to be wrapped vertically, by setting these values:
android:layout_height="wrap_content"
android:layout_width="match_parent"
You should apply these to the TextView, LinearLayout and Button elements of second level.
If you have overlapping imageviews try adding weights to them and/or changing the width to not match the parent and only wrapping the content.
please change andriod to android ( Line 14 )
Your posted code has a typo. Your fix might be as simple as replacing the line:
andriod:orientation="horizontal"
with:
android:orientation="horizontal"
Judging by the image you posted, I think you may have forgotten to add weights to occupy the free space in your Linearlayouts. Try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
andriod:orientation="horizontal"
android:layout_weight="1" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
</LinearLayout>

How to set listviews in horizontalScrollView to fill up the screen?

I have three listviews in horizontalScrollView. I want to make each of them to occupy the full screen, by including them into a linearlayout which is set to (layout_width: match_parent, layout_height: match_parent). However, it doesn't work. As you see from the screenshot, the three listviews just tightly linked with one another.
Any suggestions so that the three listviews each occupies the full screen? THx a lot.
<HorizontalScrollView
android:id="#+id/horizontalScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/page_bg_color">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tab_login_myFriends_requestList"
android:background="#ffffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tab_login_myFriends_pendingList"
android:background="#ffffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tab_login_myFriends_confirmedList"
android:background="#ffffffff" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
Use this,
http://developer.android.com/reference/android/widget/ScrollView.html#attr_android:fillViewport
Set that to true. Also your listviews should probably have a weight attribute associated with them.
But I can't really figure out what you're trying to do. Maybe provide the xml and I'll guide you further.
I think what you're looking for is this,
http://developer.android.com/training/animation/screen-slide.html

Android: HorizontalScrollBar needs snap to next item even with short scroll

I have the following layout...
<?xml version="1.0" encoding="utf-8"?>
<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">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="#+id/mygallery"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/level1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:src="#drawable/level1"
android:layout_weight = "1"
/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
The problem I am having is when I scroll, if it is not long enough, it gets stuck in the middle (between imageviews). Is there a way I can have it scroll all the way to the next item instead? Am I even using the right tools for this?
I solved this by Using ViewPager & Fragments instead of HSB.
try using wrap_content in the width of HorizontalScrollView. I hope this helps you. BestRegards

Categories

Resources