R
R
RusSanta2017-04-20 10:40:07
Android
RusSanta, 2017-04-20 10:40:07

How to align RecyclerView element to its right edge?

The situation is that certain elements need to be right aligned on the RecyclerView , but I don't understand how, none of these attributes:
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="end"
Together, or not together, they don’t work, margin works, but I don’t see the point in calculating the indents, when most likely it is possible to do everything calmly with one attribute, without
ps numbers For the elements of the right and left edges, their own templates have been created

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_gravity="end"
    android:foreground="?android:attr/selectableItemBackground"
    app:cardCornerRadius="4dp"
    app:cardElevation="1dp"
    app:cardUseCompatPadding="true">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        

        android:orientation="vertical"
        android:padding="8dp">

        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/ivAvatar"
                android:layout_width="@dimen/size_avatar_imageview"
                android:layout_height="@dimen/size_avatar_imageview"

                android:src="@mipmap/ic_launcher" />

            <TextView
                android:id="@+id/tvPhone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                
                android:layout_marginLeft="8dp"
                android:text="@string/unidentified_user"
                android:textAppearance="@style/TextAppearance.AppCompat.Title" />
        </LinearLayout>

        <TextView
            android:id="@+id/tvText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            
            android:layout_marginTop="8dp"
            
            
            android:text="New Text"
            android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

    </LinearLayout>
</android.support.v7.widget.CardView>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2017-04-20
@red-barbarian

Everything is working. Everything is right.)
In general, everything is done like this:
we make the layout of the RecyclerView element.
For example

<LinearLayout ...>
 <CardView>
<TextView />
</CardView>
</LinearLayout>

those. layout, inside the card, inside the text (or elements, etc. layout)
Then, based on the elements (R.id.text_view), we make our ViewHolder - the element that will show our data.
Then, based on the layout of the element and data, we make our own Adapter. which describes the creation of ViewHolders, and their binding to data.
Then on creation (initialization in onCreate) we set the LayoutManager for Recycler
I.e.
If we want Recycler - lines for the entire width of the screen, one by one from top to bottom, then
our element
will have
a warp height, match width.
In the editor, we will see it like that.
Recycler clones this image and substitutes data.
Comment. try to reduce the number of Layout in the layout. It is often possible to replace several with one, such as RelativeLayout. This will greatly increase performance.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question