Search code examples
androidandroid-layoutandroid-linearlayoutandroid-relativelayout

Linear Layout behind ImageView in Relative Layout


Let me explain i have a xml like this

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">
    <ImageView
      android:id="@+id/imgCircle"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/img_circle" />
    <LinearLayout
      android:id="@+id/llFirstScreen"
       android:layout_alignTop="@id/imgCircle"
       android:layout_alignBottom="@id/imgCircle"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_toRightOf="@id/imgCircle"
       android:layout_toEndOf="@id/imgCircle"
       android:background="@drawable/layout_view_round_corner"
       android:orientation="vertical">
    <TextView
       android:id="@+id/mapCurrentLocation"
       android:layout_width="match_parent"
       android:layout_height="0dp"
       android:layout_weight="1"
       android:text="TextView1"
       android:textColor="@color/lblTextColor"
       android:textSize="@dimen/lblTextLarge"
       android:textStyle="normal" >
    </TextView>
    <TextView
       android:layout_width="match_parent"
       android:layout_height="0dp"
       android:layout_weight="1"
       android:text="TextView2"
       android:textColor="@color/lblHintColor2"
       android:textSize="@dimen/lblTextMedium"
       android:textStyle="normal" >
    </TextView>
   </LinearLayout>
 </RelativeLayout>

And this gives me Image and TextViews next to it

Layout i currently have

But i want to accomplish something like this

Layout i would like to have

that TextView Background is extended (padding maybe) at the half of the Rounded Image (behind it) so that it looks like its "part" of the image. Or I was thinking of Making a view with background white that goes behind TextView so that it looks that way. But wanted to ask here maybe if there is a better way to do this.

I hope i was clear in explaining this (That is why I added pictures).


Solution

  • I have tried to use demo with your xml file and you can check below code. I had to give static height and width of the ImageView to achieve result.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
        <LinearLayout
            android:id="@+id/llFirstScreen"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/imgCarCircle"
            android:layout_alignTop="@id/imgCarCircle"
            android:layout_marginLeft="30dp"
            android:background="@color/colorAccent"
            android:orientation="vertical"
            android:paddingLeft="40dp">
    
            <TextView
                android:id="@+id/mapCurrentLocation"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:text="text1"
                android:textStyle="normal"></TextView>
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:text="text2"
                android:textStyle="normal"></TextView>
        </LinearLayout>
    
        <ImageView
            android:id="@+id/imgCarCircle"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:src="@mipmap/ic_launcher_round" />
    </RelativeLayout>