Achieve Verticle Recyclerview with Horizontal Recyclerview as row file - android

I want to achieve something like this
I tried to do with horizontal recyclerview as row file of vertical recyclerview but I am not able to achieve horizontal scroll.
It will be great if anyone helps me out
Here is the code
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="#color/colorPrimaryDark">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_player"
android:layout_width="0dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:layout_height="match_parent"
android:layout_weight="3" />
<HorizontalScrollView
android:id="#+id/horizontal"
android:layout_width="0dp"
android:layout_weight="7"
android:fillViewport="true"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/lin_main"
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_height="wrap_content">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Here I am trying to add dynamic views in LinearLyout (lin_main)

Create Your ITEM_LAYOUT which you are setting it on recycler view like this as follows.
<?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="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:padding="#dimen/_8sdp">
//YOUR VIEWS HERE
</LinearLayout>
<ScrollView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity=""
android:orientation="horizontal"
android:padding="#dimen/_8sdp">
//YOUR HORIZONTAL SCROLL VIEWS COMPONENT
</LinearLayout>
</ScrollView>
</LinearLayout>
Hope this will help. For more details share your UI xml file here.

Related

ScrollView not working in a fragment

i want to make layout scrollable with scrollview but its not working at all.tried to change scrollview with NestedScrollView but the problem still same. this layout used in fragment. put LinearLayout inside the scrollview as a view. can anyone help me to correct my code if i am doing wrong ? below is my xml code
<?xml version="1.0" encoding="utf-8"?>
<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:id="#+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="#android:color/white"
android:orientation="vertical"
tools:context=".ui.jobCalendar.JobCalendarFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.applandeo.materialcalendarview.CalendarView
android:id="#+id/calendarView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:headerColor="#color/colorPrimaryDark" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_calendar"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary">
<TextView
android:padding="10dp"
style="#style/TextContent.Black"
android:layout_marginBottom="8dp"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:text="Schedule"
android:textColor="#color/white"
android:textSize="16sp" />
</LinearLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/listJob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
tools:listitem="#layout/job_row">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
thanks in advance
Do this
1) Change root layout to RelativeLayout
2) Set height of ScrollView to wrap_content
3) Change height of ScrollView child which is LinearLayout to
match_parent
4)add this line to Host activity of that fragment
<activity
android:name="Activity_name"
android:windowSoftInputMode="stateHidden|adjustResize" />
Finally the xml looks like:-
<RelativeLayout 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:id="#+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:fillViewport="true"
android:orientation="vertical"
tools:context=".ui.jobCalendar.JobCalendarFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:fillViewport="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.applandeo.materialcalendarview.CalendarView
android:id="#+id/calendarView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:headerColor="#color/colorPrimaryDark" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_calendar"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary">
<TextView
style="#style/TextContent.Black"
android:layout_marginBottom="8dp"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:padding="10dp"
android:text="Schedule"
android:textColor="#color/white"
android:textSize="16sp" />
</LinearLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/listJob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
tools:listitem="#layout/job_row">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I think you need to get rid of those settings inside the ScrollView attribute.
Basically short it down to
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
Put the rest of the settings inside a RelativeLayout that is included inside the ScrollView like this:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
======== put all the rest of your settings from scrollvide here =====>
<CONTENT> add here the rest of your code </CONTENT>
</RelativeLayout>
</Scrollview>

scroll views and RecyclerView at same time

want to scroll RecyclerView and views in scroll view, in this code scroll only work on views but not scroll the RecyclerView or scroll hide the RecyclerView.I am using nested scrollview but same not working.
scroll views and RecyclerView like as one layout is scrolling.
<?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">
<ScrollView
android:id="#+id/scrol"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/topRl5"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/nested_scrol"
android:orientation="vertical"
android:visibility="visible">
<com.github.mikephil.charting.charts.BarChart
android:id="#+id/chart1"
android:layout_width="match_parent"
android:layout_height="#dimen/_300sdp"
android:layout_below="#+id/weekly_summary"
android:visibility="visible" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#color/grey_light"
android:gravity="center"
android:padding="#dimen/_5sdp"
android:text="تفصیلی رپورٹ"
android:textSize="#dimen/_15sdp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/daily_earning_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/scrol"
android:visibility="visible">
<include
layout="#layout/weekly_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</RelativeLayout>
Here is my RecyclerView i include it in main class
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:showIn="#layout/activity_barchart"
tools:context=".guaranteeDetails.baarChart.BarChartActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/weekly_recycler_view"
android:layout_marginRight="#dimen/_4sdp"
android:layout_marginLeft="#dimen/_4sdp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
Use should use NestedScrollView instead of ScrollView
And I would also recommend setting
Recyclerview.setNestedScrollingEnabled(false);

Scroll two horizontal listview and one vertical listview in single activity

I have to scroll both the horizontal listview and vertical listview in single activity.
Below I have posted a screenshot for that:
activity_main.xml:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/home_layout_top"
android:scrollbars="none"
>
<RelativeLayout
android:id="#+id/rl_container_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
android:id="#+id/inc_ads_horizon"
layout="#layout/ads_horizontal_listview_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp" />
<include
android:id="#+id/inc_people_know"
layout="#layout/people_you_know_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/inc_ads_horizon"
android:layout_marginTop="10dp" />
<include
android:id="#+id/inc_listview"
layout="#layout/tab_home_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/inc_people_know"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/no_user_posts_item_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/txt_no_posts_available"
android:textColor="#color/txt_common_black"
android:textSize="#dimen/txt_size" />
</RelativeLayout>
</ScrollView>
tab_home_list_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_layout_bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<ListView
android:id="#+id/lv_post_home_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="#null"
android:dividerHeight="5dp"
android:scrollbars="none"
android:transcriptMode="alwaysScroll"
android:visibility="gone" />
</LinearLayout>
ads_horizontal_listview_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_horizontalscroll_child"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#+id/rl_horizontalscroll_parent"
android:layout_marginTop="40dp">
<com.steve.thirdparty.HorizontalListView
android:id="#+id/hlv_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
people_you_know_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_horizontalscroll_second_child"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_horizontalscroll_parent"
android:layout_marginTop="40dp">
<com.steve.thirdparty.HorizontalListView
android:id="#+id/hlv_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
I tried with scrollview.It is not possible to scroll.Let me know is there any other ways to solve this issue.
If I scroll vertical listview to top, it is scrolling vertical listview only.If I am scrolling horizontal listview to the top, it is scrolling both vertical and horizontal listivew.But when I am scolling up, horizontal listview is hiden.
You can get the required views by customizing ScrollView & HorizontalScrollView.
Can check this post https://arunbadole1209.wordpress.com/2011/10/03/how-to-make-simultaneous-scrollable-views-in-android/
Use this xml layout, customize item views according to your actual need:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:nestedScrollingEnabled="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- You can define layout manager here also-->
<android.support.v7.widget.RecyclerView
android:id="#+id/ads_horizon"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/people_know"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/post_home_tab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

How to display the listview at the bottom of my activity ? There are 3 linear layouts above the listview

i am dividing my android screen into four vertical parts and i want to display the listview at the bottom of my screen, but whenever i placed it at bottom it wont aligned to the bottom. Even after i stretched it to the bottom it takes full screen. how to do that ?
You can display listview at the bottom by the following desing.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!--First Part-->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!--Second Part-->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!--Third Part-->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!--Fourth Part-->
<ListView
android:id="#+id/xListView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</LinearLayout>
this may help you
<?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="wrap_content"
android:weightSum="4"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
//first view....
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
//second view....
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
//third view....
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
//List view goes here....
</LinearLayout>
If the listview which you want at bottom always need to be seen then you should use rlativelayout. It will help you to place it properly at bottom by using this attribute android:layout_alignParentBottom="true" in your listview.
Linear layout with vertical orientation will be more helpful instead of
relative layout
<?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="wrap_content"
android:weightSum="4"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
<ListView
android:id="#+id/mListView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

How can I implement from xml file layout inside the App using Android studio?

I'm beginner in Android. I want implement this graphic layout into an Android App:
How can I generate xml to implement the layout on the picture in Android?
below is your desired layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:weightSum="3"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:background="#C3C3C3"
android:layout_height="0dp">
<ImageView
android:background="#color/black_color"
android:layout_width="match_parent"
android:src="#drawable/ic_launcher"
android:layout_height="match_parent" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_weight="2"
android:background="#FFC90E"
android:layout_height="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:textSize="20sp"
android:text="this is text view which is scrollable"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
</LinearLayout>
The total weight sum of the parent linearlayout is 3 and 1 is assigned to linear layout that contain imageview and 2 is to scroll view you can change the height of these two views by changing the values of 1 and 2 but the sum should not increase more then 3
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="sample text" />
</LinearLayout>
</ScrollView>

Categories

Resources