Firstly, I am new to android so if I have missed something basic I do apologise.
I have created a GridView to store some information. The GridView consists of a 3x6 grid. In each cell, there is an image and text directly under the image. As the GridView is so large I have implemented a scrollbar.
This is how the page should look normally and is when first loaded/selected :
Everything looks wonderful, however, when I scroll down to the bottom and then back up, the text seems to wrap up and then push the image out of place. I am not sure why this is?
This is how the page looks after I have scrolled down and they scroll back up :
For the GridView, I have an XML file with the GridView itself along with a TextView at the very top called content_rewards.xml. I have also create an XML file for each picture/text in the grid itself called relics_gridlayout.xml. I believe I am probably missing a property of the TextViews in either one of these files, however, I am not sure which one or which property. I don't think it has anything to do with the grid or adapter itself hence I will not include that code.
content_rewards.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:fitsSystemWindows="true"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="25dp">
<GridView
android:id="#+id/customgrid"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_below="#+id/os_texts"
android:columnWidth="100dp"
android:numColumns="auto_fit"
android:stretchMode="spacingWidthUniform"
android:verticalSpacing="35dp"
android:scrollbars="horizontal"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="116dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="B = 0 S = 0 G = 0"
android:textSize="24sp"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toTopOf="#+id/customgrid"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="8dp"
app:layout_constraintLeft_toLeftOf="parent"/>
</android.support.constraint.ConstraintLayout>
relics_gridlayout.xml
<?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:padding="3dp">
<ImageView
android:id="#+id/os_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_below="#+id/os_images"
android:id="#+id/os_texts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is Just Dummy Text"
android:textAlignment="center"
android:textSize="18dp"
android:textStyle="bold"/>
</RelativeLayout>
Any help would be great. Thanks.
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ECEFF1"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/app_bar_main">
<GridView
android:id="#+id/grd1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center"
android:horizontalSpacing="6dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="6dp">
</GridView>
</RelativeLayout>
This should solve your problem.
The scrolling view behavior will handle the scrolling irrespective of the size
Now add the Text view out of the Relative layout to view it always.
Or have a parent as Nested scrolling View and allow the nested scrolling enabled as false
setNestedScrollingEnabled(false)
A sample from my code that I already have used successfully to resolve such issue
Use your Grid view instead of Recycler View.
If you want the Item Text View to be always of 2 lines then set munLines="2" in the item Layout
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_container_reports"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<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:orientation="vertical">
<android.support.v7.widget.AppCompatTextView
android:id="#+id/tab_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="#string/user_reports"
android:textAllCaps="true"
android:textColor="#color/colorPrimaryDark"
android:textSize="#dimen/tab_label"
app:textAllCaps="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/reports_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="false"
android:nestedScrollingEnabled="false"
android:padding="4dp" />
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
This is a problem that i faced as well , the only solution that i could come up with was hardcoding the height of the grid item.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:padding="3dp">
A better option would be to use recycler view with a grid layout manager.
you can use LinearLayout and assign weights so that every item in your grid view occupy same space
Update the relics_gridlayout.xml with below code ( you may need to adjust gravity and layout weights)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:id="#+id/linearLayout_root_single_home_option"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/os_images"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:layout_weight="9" />
<TextView
android:id="#+id/os_texts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Just Dummy Text"
android:textSize="18dp"
android:textStyle="bold"
android:layout_weight="1" />
</LinearLayout>
Related
I have a RecyclerView inside of a NestedScrollView, my problem is that the RecyclerView is very short, only large enough to show 1 element at a time. The dataset is small (3-5 elements) so my goal is to show all elements at once.
I've tried disabling nested scrolling, changing the layout_height to wrap_content/match_parent, etc. but to no avail.
Code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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:background="#color/white"
android:paddingBottom="52dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp">
<!-- A bunch of other layouts -->
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/documents_rv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:paddingBottom="8dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#id/title"
app:layout_constraintTop_toBottomOf="#id/doc1"
tools:visibility="visible"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
Update, item xml (I know it could be replaced with just 1 TextView, but for now it will stay as is):
<?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="wrap_content"
android:layout_marginTop="4dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/doc_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_doc"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/doc_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="4dp"
android:gravity="center_vertical" />
</LinearLayout>
Not an ideal solution since it uses nested layouts, but I was able to display all items by wrapping my RecyclerView in a RelativeLayout:
<RelativeLayout
android:id="#+id/list_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:paddingBottom="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#id/title"
app:layout_constraintTop_toBottomOf="#id/title">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/documents_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
I have an app that takes a variable number of user names and builds a grid with two columns for each user. The problem is, I want the columns in the grid to have no space between each other. If they don't fill the screen, I'd like them to center on it. I've tried every suggestion I could find on Stack Overflow, but nothing has worked so far.
I changed the column width, gravity, horizontal spacing, and stretch mode. Are there any other values I'm missing that might help?
Here is the layout that includes my grid view:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">
<TextView
android:id="#+id/greetPlayers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:text="Player Names Here"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<GridView
android:id="#+id/score_gridview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:columnWidth="100dp"
android:horizontalSpacing="0dp"
android:verticalSpacing="0dp"
android:gravity="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/greetPlayers" />
<FrameLayout
android:id="#+id/scoreEntryWindow"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="64dp"></FrameLayout>
</android.support.constraint.ConstraintLayout>
And here is the layout for each item in the grid:
<?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">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="-15dp">
<ImageView
android:id="#+id/backgroundCellImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/empty_square" />
<TextView
android:id="#+id/foregroundCellContents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="1,1" />
</FrameLayout>
</LinearLayout>
Edit 20 June: changing the items in the grid view to match parent, they are now centered in the extra-wide space, but still have the space.
Link to new image - can't embed images in posts yet.
I am building a daily schedule like for students. This schedule is in a fragment. I need a sticky header with seven day labels and then the items need to scroll underneath, all at once. In addition I need the entire view to scroll horizontally.
Currently I have a HorizontalScrollView, some nested LinearLayouts, and a NestedScrollView. There are 7 RecyclerViews that are children of the NestedScrollView, one for each day of the week. This is so that I can call setNestedScrollingEnabled(false) on each RecyclerView so they scroll together. Currently the result is that the NestedScrollView clips the RecyclerViews to 1 item and no scrolling is possible. If I remove the NestedScrollView The RecyclerViews all scroll individually which is not what I want.
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:elevation="4dp" />
<FrameLayout
android:layout_below="#id/toolbar"
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
fragment_schedule.xml
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView 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"
xmlns:tools="http://schemas.android.com/tools"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ProgressBar
android:id="#+id/loading"
android:layout_width="74dp"
android:layout_height="74dp"
android:visibility="gone"
android:layout_gravity="center"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
...7 ImageViews representing days of week...
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_marginTop="8dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/sunday_list"
android:layout_width="84dp"
android:layout_height="wrap_content"
tools:background="#color/accent_gold"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/monday_list"
android:layout_width="84dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
tools:background="#color/accent_gold"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/tuesday_list"
android:layout_width="84dp"
android:layout_marginLeft="8dp"
android:layout_height="wrap_content"
tools:background="#color/accent_gold"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/wednesday_list"
android:layout_width="84dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
tools:background="#color/accent_gold"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/thursday_list"
android:layout_width="84dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
tools:background="#color/accent_gold"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/friday_list"
android:layout_width="84dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
tools:background="#color/accent_gold"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/saturday_list"
android:layout_width="84dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
tools:background="#color/accent_gold"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</HorizontalScrollView>
The only thing of note in the fragment class is that I call setNestedScrolledEnabled(false) after populating and attaching all of the adapters.
Any insight is greatly appreciated!
The solution in this case is that I was thinking about the requirements too rigidly. I changed my layout to consists of a The header linear layout, a scrollview, and a horizontal recycler view, with each day being an item. In the adapter the item layout is simply a LinearLayout that I programmatically add the class views to(as there is a finite number of classes per day). Scrolling works in both directions. I will retitle the question so hopefully someone can find this working towards similar requirements.
Fragment xml
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView 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"
xmlns:tools="http://schemas.android.com/tools"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ProgressBar
android:id="#+id/loading"
android:layout_width="74dp"
android:layout_height="74dp"
android:visibility="gone"
android:layout_gravity="center"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
...Image Views Representing Days of Week...
</LinearLayout>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/day_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</ScrollView>
</LinearLayout>
</HorizontalScrollView>
RecyclerViewItem.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="84dp"
android:layout_height="match_parent"
android:id="#+id/item_schedule_layout"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="0dp">
</LinearLayout>
Then programmatically add views to the LinearLayout. My views for each class were complex so I created a custom view based on the layout I needed for each class and then was able to just define a new instance in a for loop and add it to the LinearLayout.
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 vertical RecyclerView using a GridLayoutManager. I want each column to be centered, but the columns begin all the way on the left. In the following picture you can see what I'm talking about. I used the ugly color scheme to illustrate the columns and background. The green is the background for each item in the RecyclerView, the red is the background of the RecyclerView itself:
http://imgur.com/a/J3HtF
I'm setting it up with:
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
Here's the column_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="120dp"
android:layout_height="180dp"
android:orientation="vertical"
android:padding="4dp">
<ImageView
android:id="#+id/movie_column_photo"
android:layout_width="80dp"
android:layout_height="120dp"/>
<TextView
android:id="#+id/movie_column_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Here's the recyclerview xml:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/company_details_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
Try letting the column item fill the width of the column while centering everything inside:
<?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="180dp"
android:orientation="vertical"
android:padding="4dp">
<ImageView
android:id="#+id/movie_column_photo"
android:layout_width="80dp"
android:layout_height="120dp"
android:layout_gravity="center_horizontal"/>
<TextView
android:id="#+id/movie_column_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"/>
</LinearLayout>
To restate #kris larson's answer;
If you are using ConstraintLayout, adding android:layout_gravity="center" or android:layout_gravity="center_horizontal" to the parent layout in item's XML would be enough (the first parent in hierarchy).
In your case, the codes would be something similar to this:
<android.support.constraint.ConstraintLayout
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="match_parent"
android:layout_height="180dp"
android:orientation="vertical"
android:padding="4dp"
android:layout_gravity="center">
<ImageView
android:id="#+id/movie_column_photo"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="80dp"
android:layout_height="120dp"/>
<TextView
android:id="#+id/movie_column_title"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.constraint.ConstraintLayout>
Simply set the width of the root layout for your column_item.xml to match_parent will center RecyclerView items horizontally.
Wrap your recyclerview inside the constraintlayout, something like this:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/book_list"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:spanCount="2" />
Hope it helps!!