Home > Software design >  overlay 2 textview in one linear layout
overlay 2 textview in one linear layout

Time:03-02

Is it possible to overlay 2 textviews in one linear layout? I want them in the same position but they have to be in one linear layout

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp">

            <Textview
                android:id="@ id/tv1"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
               <Textview
                android:id="@ id/tv2"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </LinearLayout>

CodePudding user response:

You don't need Linear layout there if you want it to be overlapping .. you can use RelativeLayout or FrameLayout

<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<TextView
    android:id="@ id/tv1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="asdf"/>
<TextView
    android:id="@ id/tv2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="sfgsfg"/>

CodePudding user response:

sadly they can't in LinearLayout, but you can use FrameLayout - without an easy option for placing child Views next to each other (as in LinearLayout) - or RealtiveLayout - which have some params for placing one View next to/above another when needed

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp">

    <Textview
        android:id="@ id/tv1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
        
    <Textview
        android:id="@ id/tv2"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>
  • Related