I want the image and text together horizontal, the picture is above the text, in RecycleView and CardView in Android Studio

I want the image and text together horizontal, the picture is above the text, in RecycleView and CardView in Android Studio

before do any things please use ConstraintLayout instead of LinearLayout or RelativeLayout

and for this sample item you can try like this

it`s for item.xml

<androidx.cardview.widget.CardView 
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=wrap_content
android_layout_margin=4dp>


<androidx.constraintlayout.widget.ConstraintLayout
    android_layout_width=match_parent
    android_layout_height=100dp>

    <ImageView
        android_id=@+id/imageView
        android_layout_width=90dp
        android_layout_height=90dp
        android_layout_marginStart=8dp
        android_layout_marginTop=8dp
        android_layout_marginEnd=8dp
        android_layout_marginBottom=8dp
        android_scaleType=centerInside
        app_layout_constraintBottom_toBottomOf=parent
        app_layout_constraintEnd_toEndOf=parent
        app_layout_constraintHorizontal_bias=0.0
        app_layout_constraintStart_toStartOf=parent
        app_layout_constraintTop_toTopOf=parent
        tools_srcCompat=@tools:sample/avatars />

    <TextView
        android_id=@+id/textView
        android_layout_width=wrap_content
        android_layout_height=wrap_content
        android_layout_marginStart=16dp
        android_layout_marginTop=8dp
        android_layout_marginBottom=8dp
        android_text=TextView
        app_layout_constraintBottom_toBottomOf=parent
        app_layout_constraintEnd_toEndOf=parent
        app_layout_constraintHorizontal_bias=0.0
        app_layout_constraintStart_toEndOf=@+id/imageView
        app_layout_constraintTop_toTopOf=parent />

</androidx.constraintlayout.widget.ConstraintLayout> 
</androidx.cardview.widget.CardView>

and it`s for main.xml

<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
tools_context=.MainActivity>

<TextView
    android_id=@+id/textHeader
    android_layout_width=wrap_content
    android_layout_height=wrap_content
    android_layout_marginTop=8dp
    android_text=Header
    app_layout_constraintBottom_toBottomOf=parent
    app_layout_constraintLeft_toLeftOf=parent
    app_layout_constraintRight_toRightOf=parent
    app_layout_constraintTop_toTopOf=parent
    app_layout_constraintVertical_bias=0.0 />

<androidx.recyclerview.widget.RecyclerView
    android_layout_width=match_parent
    android_layout_height=0dp
    android_layout_marginTop=8dp
    app_layout_constraintBottom_toBottomOf=parent
    app_layout_constraintEnd_toEndOf=parent
    app_layout_constraintStart_toStartOf=parent
    app_layout_constraintTop_toBottomOf=@+id/textHeader /> 
</androidx.constraintlayout.widget.ConstraintLayout>

Add this in hindu_design layout

    <androidx.cardview.widget.CardView
    xmlns_android=http://schemas.android.com/apk/res/android
    xmlns_card_view=http://schemas.android.com/apk/res-auto
    android_layout_width=match_parent
    android_layout_height=wrap_content
    card_view_cardUseCompatPadding=true
    card_view_cardCornerRadius=5dp
    card_view_cardElevation=5dp
    card_view_cardBackgroundColor=#ffff>

    <RelativeLayout
        android_layout_width=match_parent
        android_layout_height=wrap_content
        android_padding=10dp
        android_orientation=horizontal>
        <ImageView
            android_layout_marginTop=-12dp
            android_paddingRight=1dp
            android_id=@+id/playerImage
            android_layout_alignParentLeft=true
            android_layout_alignParentStart=true
            android_layout_width=100dp
            android_layout_height=100dp

            android_src=@drawable/search/>


        <LinearLayout
            android_layout_width=match_parent
            android_layout_height=wrap_content
            android_orientation=vertical
            android_gravity=center
            android_layout_marginLeft=5dp
            android_layout_marginStart=15dp>

            <RelativeLayout
                android_layout_width=match_parent
                android_layout_height=match_parent>




            <TextView

                android_lineSpacingExtra=5dp
                android_id=@+id/nameTxt
                android_text=Sylhet Students Association
                android_textStyle=bold
                android_textSize=18sp
                android_paddingLeft=77dp
                android_paddingTop=22dp
                android_textColor=@android:color/black
                android_layout_width=match_parent
                android_layout_height=wrap_content
                android_typeface=serif/>

            </RelativeLayout>   
        </LinearLayout>
    </RelativeLayout>
</androidx.cardview.widget.CardView>

I want the image and text together horizontal, the picture is above the text, in RecycleView and CardView in Android Studio

Leave a Reply

Your email address will not be published.