繁体   English   中英

android:layout_alignParentTop =“ true”和android:layout_centerVertical =“ true”不会将imageView设置在屏幕顶部居中

[英]android:layout_alignParentTop=“true” and android:layout_centerVertical=“true” do not set the imageView centered at the the top of the screen

我有一个非常简单的布局,我试图将imageView居中在屏幕中间,但与顶部对齐。 我尝试使用以下内容,但是它似乎不起作用,并且不确定为什么:imageView出现在左上角,而不是居中并与顶部对齐。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"

        >

    <ImageView
        android:id="@+id/ic_launcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" 
        android:layout_centerVertical="true"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

我正在尝试将imageView居中在屏幕中间,但与顶部对齐。

ImageView使用android:layout_centerHorizontal="true"代替android:layout_centerVertical="true" 因此,以下应该是您的XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"

        >

    <ImageView
        android:id="@+id/ic_launcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" 
        android:layout_centerHorizontal="true"
        android:src="@drawable/backspace_icon" />

</RelativeLayout>

希望能帮助到你。

暂无
暂无

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

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