1

Suppose I have TextView A and TextView B in my activity layout. What java or xml code do I use to make TextViewA appear in the foreground and TextView B in the background, relative to each other? In other words, when I move TextView A in the layout till it overlaps with TextView B, what java or xml code should I use to make TextView A hide TextView B from view?

user1892364
  • 259
  • 2
  • 12
Steven
  • 289
  • 2
  • 5
  • 14
  • use relative layout to over lape place the two – Iamat8 Jun 27 '18 at 13:22
  • Can someone please upvote my question. I'm getting blocked again for three days by StackOverflow because "this isn't a good question". My mum always told me there are no bad questions, just bad answers. Guess StackOverflow says she was wrong. – Steven Jun 27 '18 at 18:30
  • "Will you upvote my bad question so the site will let me keep writing bad questions?" This is a hilarious request. The point of throttling users who write bad questions is not to punish you, it's to reduce the number of bad questions. There are lots of resources on how to write better questions, such as [ask]. – trent Jun 27 '18 at 19:03

3 Answers3

3

You could toggle the text views elevation.

textViewA.elevation = 0.0f
textViewB.elevation = 1.0f 
tgrable
  • 1,013
  • 1
  • 7
  • 15
2

You juste have to place your TextView A after the TextView B in your layout (it will draw it above) and if you want to hide the TextView B, add a background to your TextView A like :

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

       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:background="#FFFFFF"
           android:text="B" />

       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:background="#FFFFFF"
           android:text="A" />

   </RelativeLayout>
Bubu
  • 1,533
  • 14
  • 14
0

You could also use ViewSwitcher if your goal is to have two views with one of them visible. See:

How to use Android ViewSwitcher?

https://developer.android.com/reference/android/widget/ViewSwitcher

user1892364
  • 259
  • 2
  • 12