[英]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.