0

TextViews我有两个Activity(我们称它们为 TV1 和 TV2),它们都属于不同的RelativeLayouts. 我创建了一个TranslateAnimation将 TV1 从其位置移动到 TV2 的位置。问题是,当 TV1 到达 TV2's 时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>

[编辑2]

简化版:

<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>
4

2 回答 2

2

这可能与各个布局元素的 z 顺序(即垂直堆叠)有关。两种解决方案:

(1)更改您的 java 代码中的 z 顺序,以便将您想要在顶部的视图移动到前面。在您的情况下,您将想要将包含TextView您想要的顶部的整个相对布局移动到前面。仅移动文本视图本身是行不通的。

(2)控制 xml 中的 z 顺序。默认情况下,在您的 XML 文件中向下添加的视图将在 z 顺序中更高。尝试交换相对布局的位置,看看它是否有效。

于 2013-03-28T12:17:39.343 回答
0

尝试在您的 xml 中使用 android:elevation。

对于 TV1,提供 android:elevation = "1dp"

对于 TV2,提供 android:elevation = "0dp"

于 2016-07-27T17:09:34.570 回答