Android:如何修复与我的文本重叠的图像?

Android:如何修复与我的文本重叠的图像?,android,xml,Android,Xml,如何修复此错误。基本上,图像与文本重叠。 我们可以用XML解决这个问题吗 这是代码(当然,它是不完整的) 错误截图: 不确定您到底在寻找什么,但我可以想出两个快速解决方案: 首先,您需要将TextView的id标记更改为其他标记,它当前与您的按钮具有相同的id,这不好。我想你的意思是centerText 1。您希望文本视图显示在图像视图 要实现这一点,实际上只需将TextViewXML元素移动到ImageView元素下面。因为视图是按照XML布局从上到下的顺序“分层”的,所以这将把TextV

如何修复此错误。基本上,图像与文本重叠。 我们可以用XML解决这个问题吗

这是代码(当然,它是不完整的)


错误截图:

不确定您到底在寻找什么,但我可以想出两个快速解决方案:

首先,您需要将
TextView
id
标记更改为其他标记,它当前与您的
按钮具有相同的
id
,这不好。我想你的意思是
centerText

1。您希望
文本视图
显示在
图像视图

要实现这一点,实际上只需将
TextView
XML元素移动到
ImageView
元素下面。因为视图是按照XML布局从上到下的顺序“分层”的,所以这将把
TextView
放在
ImageView
的顶部

2。您希望图像视图不与文本视图重叠

您可以将
android:layout_over=“@+id/centerButton”
更改为
android:layout_over=“@+id/centerText”
,其中
centerText
是您的
TextView
,当然带有正确的
id
标记


希望这能解决你的问题!如果没有,请更具体地说明您希望实现的目标

将顺序TextView->ImageView更改为ImageView->TextView

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFCC0000"
    >

    <ImageView
        android:scaleType="centerInside"
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/Cat"
        android:layout_above="@+id/centerButton"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="39dp" />


    <TextView
        android:background="#55000000"
        android:id="@+id/centerButton"
        android:text="RELATIVE LAYOUT RULES!"
        android:textSize="33dp"
        android:textColor="#FFFFFF"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"/>

    <Button
        android:layout_margin="40dp"
        android:padding="20dp"
        android:layout_below="@+id/centerButton"
        android:layout_centerInParent="true"
        android:text="PUSH ME!"
        android:textSize="30dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button4" />



</RelativeLayout>


Android在XML文件中自上而下以其他方式绘制布局。如果您想在上面绘制TextView,您需要将其放在底部。

这可能会有所帮助:@Xedon您可以共享@drawable/Cat图像吗看起来您的TextView位于imageview后面。尝试将textview代码放在xml中的imageview下面。这将使文本视图出现在图像的前面我已经尝试了您共享的布局。它起作用了。这不是需要刷新的预览吗?它如何在实际设备上显示?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFCC0000"
    >

    <ImageView
        android:scaleType="centerInside"
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/Cat"
        android:layout_above="@+id/centerButton"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="39dp" />


    <TextView
        android:background="#55000000"
        android:id="@+id/centerButton"
        android:text="RELATIVE LAYOUT RULES!"
        android:textSize="33dp"
        android:textColor="#FFFFFF"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"/>

    <Button
        android:layout_margin="40dp"
        android:padding="20dp"
        android:layout_below="@+id/centerButton"
        android:layout_centerInParent="true"
        android:text="PUSH ME!"
        android:textSize="30dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button4" />



</RelativeLayout>