[英]Android translate animation: moved view is overlapped
我的Activity
有兩個TextViews
(分別稱為TV1和TV2),它們分別屬於不同的RelativeLayouts
。 我創建了一個TranslateAnimation
,將TV1從其位置移動到TV2的位置。 問題是,當TV1到達TV2的RelativeLayout
,它就在其下方(移動的TextView
與TV2的布局重疊),我希望TV1在此布局上方。 有什么辦法把它擺在前面嗎?
謝謝!
[編輯]
我添加我的布局代碼。 我想將timeText移到numTimeValue 。 如您所見,timeText在numTimeValue之后聲明。 另外,我嘗試了這個:
mTimeTextView.bringToFront();
((View)mTimeTextView.getParent()).bringToFront();
而且仍然重疊。
<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]
簡化版:
<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>
這可能與各個布局元素的z順序(即垂直堆疊)有關。 兩種解決方案:
(1) 在Java代碼中更改z順序,以便將要放在頂部的視圖移到最前面。 在您的情況下,您將想要將包含您想要的TextView
的整個相對布局移到最前面。 僅移動文本視圖本身是行不通的。
(2) 在xml中控制z順序 。 默認情況下,在XML文件的最下方添加的視圖在z順序中將更高。 嘗試交換相對布局的位置,看看是否可行。
嘗試在xml中使用android:elevation。
對於TV1,請提供android:elevation =“ 1dp”
對於TV2,請提供android:elevation =“ 0dp”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.