Search code examples
androidxmltextviewoverlayandroid-relativelayout

Make a text view overlay another text view


I am trying to make a text view to overlay the above text view, I have tried the text align with no success; I can accomplish this by adding a large amount of padding but I do not want to use padding because I ran into other issues in android variety in screen sizes. I will post an image of what I'm trying to do and also post then XML code. Looking forward to some help here, thanks in advance.

Image(I am trying to make that black bar with the text android /Design overlay the above area that says busybusy Development as of right now the black text view is just pushing the above text view up were I would like it to just overlay but stays at the same position) https://i.sstatic.net/sokN1.jpg

        <?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="match_parent"
        android:orientation="vertical">
    
    
    
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
    
            <TextView
                android:id="@+id/org_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="4dp"
                android:layout_marginLeft="4dp"
                android:layout_marginRight="4dp"
                android:gravity="center_horizontal"
                android:paddingTop="42dp"
                android:paddingBottom="42dp"
                android:background="@drawable/dashboard_business_image"
                android:textColor="@color/busy_black"
                android:textStyle="bold"
                android:textAppearance="?android:attr/textAppearanceMedium">
            </TextView>
        
            <TextView
                android:id="@+id/project_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:layout_below="@id/org_name"
                android:layout_marginRight="4dp"
                android:gravity="center_horizontal"
                android:layout_gravity="bottom"
                android:paddingTop="2dp"
                android:paddingBottom="2dp"
                android:background="@color/busy_translucent_black"
                android:textColor="@color/busy_white"
                android:textStyle="normal"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:visibility="gone">
            </TextView>
        </RelativeLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical">
         
            <include layout="@layout/dashboard_clock_in_button" />
            <include layout="@layout/dashboard_clock_out_button" />
            <include layout="@layout/dashboard_paused_button" />
    
            <ListView
                android:id="@+id/action_list"
                android:layout_width="match_parent" 
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:layout_marginRight="4dp"
                android:divider="@color/busy_divider_color"
                android:dividerHeight="0dp">
            </ListView>
    
        </LinearLayout>
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginLeft="4dp"
            android:layout_marginRight="4dp"
            android:layout_weight="0"
            android:gravity="center_horizontal"
            android:paddingTop="32dp"
            android:paddingBottom="32dp"
            android:background="@color/busy_white"
            android:textColor="@color/busy_black"
            android:textStyle="bold"
            android:textAppearance="?android:attr/textAppearanceMedium" />
        
    </LinearLayout>

Solution

  • Reading this, it appears you want the project_name view to overlay the org_name view. You can do this by aligning the bottom of the views.

    Change this line:

    android:layout_below="@id/org_name"
    

    To this:

    android:layout_alignBottom="@id/org_name"
    

    That will align the bottom of the two views, effectively placing project_name on top of the org_name view.