Placing horizontal recyclerview at a specific position using ConstraintLayout

I want to place my horizonatl recyclerview at 30% screen width from start

<android.support.constraint.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">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:orientation="horizontal"
        android:paddingStart="20dp"
        android:paddingEnd="20dp"
        android:background="@android:color/white"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/guideline" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.3" />

</android.support.constraint.ConstraintLayout>

But it is not recyclerview not appearing on screen working any idea how to achieve this.

You never gave your recyclerView a vertical constraint so what happened is that at the run time your recyclerView just jumped to the top of the screen. When I copied your code I saw this error:

This view is not constrained vertically: at runtime, it will jump to the top unless you add a vertical constraint

Some tip - if you see the red line on your view in the XML/the red warning button from the design you should really look at the error and change your layout accordingly.

And of course, I won't leave you without a good working layout - here is the layout that I made for the recyclerView to start at 30% of the screen, I have checked it and its working. (i was working with androidx but just change it to the support library if you want)

<androidx.constraintlayout.widget.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">

<androidx.constraintlayout.widget.Guideline
    android:id="@+id/guideline2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:layout_constraintGuide_percent="0.3"/>

<androidx.recyclerview.widget.RecyclerView
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="16dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.506"
    app:layout_constraintStart_toStartOf="@+id/guideline2"
    app:layout_constraintTop_toTopOf="parent"
    android:background="@color/colorPrimaryDark"/>

Build a Responsive UI with ConstraintLayout, I want to place my horizonatl recyclerview at 30% screen width from start < android.support.constraint.ConstraintLayout� Within a ConstraintLayout, you can animate changes to the size and position of elements by using ConstraintSet and TransitionManager. Note: TransitionManager is available in the Support Library for Android 4.0 (API level 14) or higher.

your RecyclerView is missing the vertical constraints; Add at least one so that the view can be rendered.

constrained to top:

app:layout_constraintTop_toTopOf="parent"

if you want it to use the whole parent, add these too:

android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"

Use ConstraintLayout to design your Android views, Remove the ConstraintLayout and use Linearlayout instead, than use the android:weight= property accordingly in both guideline and RecyclerView. This example demonstrate about How to use Constraint Layout with recyclerview. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.

Remove the ConstraintLayout and use Linearlayout instead, than use the android:weight= property accordingly in both guideline and RecyclerView.

Using the RecyclerView, Build a Responsive UI with ConstraintLayout Part of Android Jetpack. To define a view's position in ConstraintLayout , you must add at least one horizontal and one want to constrain a view to the a set of views rather than to one specific view. Instead of adding constraints to every view as you place them in the layout,� In this video I show you how to use a Horizontal RecyclerView to display list items with an image and text. You'll learn to build a recyclerview adapter class from scratch and display images and text.

This will work fine for you

<android.support.constraint.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">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:clipToPadding="false"
        android:orientation="horizontal"
        android:paddingStart="20dp"
        android:paddingEnd="20dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="@id/guideline"
        app:layout_constraintBottom_toBottomOf="parent"
        />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
       app:layout_constraintGuide_percent=".3" />


</android.support.constraint.ConstraintLayout>

Make View fill space leftover in parent view using ConstraintLayout , Learn to automatically constrain UI elements to the layout. How to place and resize elements in the layout. How to add constraints in order to position and align� Using a RecyclerView with LinearLayoutManager provides functionality like the older ListView layout. GridLayoutManager arranges the items in a two-dimensional grid, like the squares on a checkerboard. Using a RecyclerView with GridLayoutManager provides functionality like the older GridView layout.

Exploring the new Android ConstraintLayout, A layout manager positions item views inside a RecyclerView and determines when to reuse item LinearLayoutManager shows items in a vertical or horizontal scrolling list. <androidx.constraintlayout.widget. necessary to ensure that animation effects are performed in a specific sequence (remove, move, and add). Overviews. The RecyclerView is a ViewGroup that renders any adapter-based view in a similar way. It is supposed to be the successor of ListView and GridView.One of the reasons is that RecyclerView has a more extensible framework, especially since it provides the ability to implement both horizontal and vertical layouts.

Android ConstraintLayout Example Tutorial, Make View fill space leftover in parent view using ConstraintLayout with specific height or width while the next view beside/below/above it should just The physics is like telling android to place the RecyclerView just below� As we already know that recyclerView has a smooth scrolling by itself but when we need to put recyclerView within any scrollView it will not work like the below code snippet: The solution for this is…

Android constraintlayout vertical scroll, Horizontal Bias. This allows us to position a view along the horizontal axis using a bias value, this will be relative to it's constrained position. In this tutorial we are going to see how to merge multiple recyclerview in only one layout. what problem occurs when we used multiple recyclerview in a single layout. It doesn’t scroll smoothly; 2nd or third recyclerview gets hide and does not comes up at the time of scrollin

Comments
  • not working for me I want height wrap_content for recyclerview
  • And when you change your height to wrap_content , do you not see your view?
  • And do you have items in your recyclerView? or currently nothing? anyway try to look at this thread explaining wrap content in recyclerVIew
  • not working for me I want height wrap_content for recyclerview
  • I think this answer may help you better stackoverflow.com/a/42762605/2811504 ;
  • Hey Bhavik Parmar, I already posted a working example with constraint layout below, please do not disqualify constraint layout - it is a great and easy tool to learn and it gives you the option to support different screen sizes.
  • There are already 2 answers that are very similar to yours, could it be that you misunderstood the question? you placed horizontally Guideline and not vertical as he asked for.