简体   繁体   English

Android:中心屏幕中的ImageView

[英]Android: ImageView in center screen

I have a background image in full screen with a RelativeLayout . 我有一个带有RelativeLayout全屏背景图像。 And other image (100x100) in an ImageView . 以及ImageView中的其他图像(100x100)。

I want to put the ImageView in center screen. 我想将ImageView放在中心屏幕中。 But my image shows top left. 但是我的图像显示在左上方。

What is the problem? 问题是什么?

XML XML格式

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fondo_inicio" >

<ImageView android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_gravity="center"
    android:gravity="center"
    android:background="@drawable/icono_inicio"/>

</RelativeLayout>

试试这个到你的ImageView

android:layout_centerInParent="true"



Add the following to the ImageView. 将以下内容添加到ImageView。

android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/fondo_inicio" >

<ImageView android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_centerInParent="true"
     android:background="@drawable/icono_inicio"/>

</RelativeLayout>

用户的layout_gravitygravityRelativeLayout情况下不起作用,因此只需使用

Layout_centerInParent = "true"
<ImageView
        android:id="@+id/pic_id"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitCenter"
        android:src="@drawable/pic" />

尝试这个

android:layout_gravity="center"

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

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