Reputation: 8145
I have two TextViews
in my Activity
(let's call them TV1 and TV2), both belonging to different RelativeLayouts
. I created a TranslateAnimation
to move TV1 from its location to TV2's location. The problem is that, when TV1 reaches TV2's RelativeLayout
, it gets under it (the moved TextView
is overlapped by TV2's layout), and I want TV1 to be above this layout. Is there any way to bring it to front?
Thanks!
[EDIT]
I add my layout code. I want to move timeText to numTimeValue. As you can see, timeText is declared after numTimeValue. Also, I tried this:
mTimeTextView.bringToFront();
((View)mTimeTextView.getParent()).bringToFront();
and it's still overlapped.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/outer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/pointsLayout"
style="@style/ScoreBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/numCorrectLayout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="@+id/numCorrectTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/num_correct_title"
android:textSize="16sp" />
<TextView
android:id="@+id/numGuessed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="22sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/numTimeLayout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="@+id/numTimeTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/num_time_title"
android:textSize="16sp" />
<TextView
android:id="@+id/numTimeValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="22sp" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="@+id/timeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ProgressBar
android:id="@+id/time_progbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/timeText"
android:indeterminateDrawable="@android:drawable/progress_indeterminate_horizontal"
android:indeterminateOnly="false"
android:maxHeight="20dip"
android:minHeight="20dip"
android:padding="15dp"
android:progressDrawable="@drawable/time_progressbar" />
<TextView
android:id="@+id/timeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:textSize="30sp" />
</RelativeLayout>
</LinearLayout>
<ImageView
android:id="@+id/movieImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp"
android:contentDescription="@string/movie_to_guess" />
</RelativeLayout>
[EDIT2]
Simplified version:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/game_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/pointsLayout"
style="@style/ScoreBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal" >
<TextView
android:id="@+id/numTimeValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="22sp" />
<!-- </LinearLayout> -->
</LinearLayout>
<RelativeLayout
android:id="@+id/timeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/pointsLayout"
android:orientation="horizontal" >
<ProgressBar
android:id="@+id/time_progbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/timeText"
android:indeterminateDrawable="@android:drawable/progress_indeterminate_horizontal"
android:indeterminateOnly="false"
android:maxHeight="20dip"
android:minHeight="20dip"
android:padding="15dp"
android:progressDrawable="@drawable/time_progressbar" />
<TextView
android:id="@+id/timeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:textSize="30sp" />
</RelativeLayout>
<ImageView
android:id="@+id/movieImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/timeLayout"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp"
android:contentDescription="@string/movie_to_guess" />
</RelativeLayout>
Upvotes: 0
Views: 3268
Reputation: 21
Try using android:elevation in your xml.
For TV1, provide android:elevation = "1dp"
For TV2, provide android:elevation = "0dp"
Upvotes: 0
Reputation: 7663
This might be related to the z-order, i.e. vertical stacking, of the respecive layout elements. Two solutions:
(1) Change the z-order in your java code so that the view you want to have on top is moved to the front. In your case you are going to want to move the entire relative layout that contains the TextView
you want on top to the front. Moving just the text view itself will not work.
(2) Control the z-order within the xml. By default views added further down in your XML file will be higher up in the z-order. Try swaping the position of the relative layouts and see if it works.
Upvotes: 2