Java RelativeLayout-android:layout_centerHorizontal=";“真的”;android:layou centerVertical=";“真的”;不要将图像视图居中

Java RelativeLayout-android:layout_centerHorizontal=";“真的”;android:layou centerVertical=";“真的”;不要将图像视图居中,java,android,android-layout,Java,Android,Android Layout,出于某种奇怪的原因,android:layout\u centerHorizontal=“true”和android:layout\u centerVertical=“true”不要将图像视图居中 有什么建议吗 图像卡在屏幕的左上角,无法按预期居中 资料来源: *<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andr

出于某种奇怪的原因,
android:layout\u centerHorizontal=“true”
android:layout\u centerVertical=“true”
不要将
图像视图居中

有什么建议吗

图像卡在屏幕的左上角,无法按预期居中

资料来源:

*<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8sp"
    android:layout_marginLeft="8sp"
    android:layout_marginRight="8sp"
    android:layout_marginTop="8sp"
    android:background="@drawable/background"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/emblem"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:adjustViewBounds="true"
            android:scaleType="fitStart"
            android:src="@drawable/apn_app_logo" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/start2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="8sp"
        android:layout_toRightOf="@id/start" >

        <Button
            android:id="@+id/go_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:background="@drawable/apn_app_go_button" />

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/go_button"
            android:layout_marginRight="8sp"
            android:layout_marginTop="8sp"
            android:gravity="center"
            android:text="@string/start_text"
            android:textColor="#000000"
            android:textSize="18sp" />
    </RelativeLayout>

</RelativeLayout>*
*
*

您不能在线性布局中使用下面的android:layout\u。您可以将这两个项目放在RelativeLayout中,也可以将LinearLayout从“水平”更改为“垂直”,如下所示:

<LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:orientation="vertical" >

中心水平移动到相对布局。当前,您正在图像视图中居中放置图像(基本上是在视图中居中放置图像),您需要的是相对布局,以使内容居中

尝试:


另一个选择是:

<RelativeLayout
        android:id="@+id/start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
       >

        <ImageView
            android:id="@+id/emblem"
            android:layout_width="match_parent" //change to match_parent
            android:layout_height="match_parent" //change to match_parent
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:adjustViewBounds="true"
            android:scaleType="fitStart"
            android:src="@drawable/apn_app_logo" />
    </RelativeLayout>


第二个选项设置
图像视图的宽度和高度以匹配
相对视图
,如果将
线性布局
方向更改为垂直,则允许您在
图像视图中使用
中心水平
中心垂直
,它会自动把它放在按钮下面。在此之后,您可以使用
layout\u gravity
居中。具有imageView的RelativeLayout未定位在所需的父RelativeLayout中。它只是在尚未定位的子布局中居中。因此,子布局可能与图像的大小完全相同。尝试将imageView的RelativeLayout设置为以父视图为中心。下次修复原始问题并想提出完全不同的问题时,只需编写一个新问题。“编辑”不应该完全改变问题。在你发布此消息前几秒钟,我更新了我的问题。。。(我想你可能想更新你的答案)这会很有帮助:)
<RelativeLayout
        android:id="@+id/start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
       >

        <ImageView
            android:id="@+id/emblem"
            android:layout_width="match_parent" //change to match_parent
            android:layout_height="match_parent" //change to match_parent
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:adjustViewBounds="true"
            android:scaleType="fitStart"
            android:src="@drawable/apn_app_logo" />
    </RelativeLayout>