简体   繁体   English

Android翻译动画:移动的视图重叠

[英]Android translate animation: moved view is overlapped

I have two TextViews in my Activity (let's call them TV1 and TV2), both belonging to different RelativeLayouts . 我的Activity有两个TextViews (分别称为TV1和TV2),它们分别属于不同的RelativeLayouts I created a TranslateAnimation to move TV1 from its location to TV2's location. 我创建了一个TranslateAnimation ,将TV1从其位置移动到TV2的位置。 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. 问题是,当TV1到达TV2的RelativeLayout ,它就在其下方(移动的TextView与TV2的布局重叠),我希望TV1在此布局上方。 Is there any way to bring it to front? 有什么办法把它摆在前面吗?

Thanks! 谢谢!

[EDIT] [编辑]

I add my layout code. 我添加我的布局代码。 I want to move timeText to numTimeValue . 我想将timeText移到numTimeValue As you can see, timeText is declared after numTimeValue. 如您所见,timeText在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] [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>

This might be related to the z-order, ie vertical stacking, of the respecive layout elements. 这可能与各个布局元素的z顺序(即垂直堆叠)有关。 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. (1) 在Java代码中更改z顺序,以便将要放在顶部的视图移到最前面。 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. 在您的情况下,您将想要将包含您想要的TextView的整个相对布局移到最前面。 Moving just the text view itself will not work. 仅移动文本视图本身是行不通的。

(2) Control the z-order within the xml . (2) 在xml中控制z顺序 By default views added further down in your XML file will be higher up in the z-order. 默认情况下,在XML文件的最下方添加的视图在z顺序中将更高。 Try swaping the position of the relative layouts and see if it works. 尝试交换相对布局的位置,看看是否可行。

Try using android:elevation in your xml. 尝试在xml中使用android:elevation。

For TV1, provide android:elevation = "1dp" 对于TV1,请提供android:elevation =“ 1dp”

For TV2, provide android:elevation = "0dp" 对于TV2,请提供android:elevation =“ 0dp”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM