Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中,将ImageView置于另一个ImageView内_Android_Xml_Imageview - Fatal编程技术网

在Android中,将ImageView置于另一个ImageView内

在Android中,将ImageView置于另一个ImageView内,android,xml,imageview,Android,Xml,Imageview,我必须把一个图像视图放在另一个图像视图中。它比较小,必须正好在中心。我对两幅图像都进行了不同屏幕分辨率的缩放,但我只能在一部手机上进行测试,我想知道我是否使用dpi设置了第二幅图像的高度和宽度,以适合我的屏幕分辨率,它是否会在所有屏幕上完美匹配,或者安卓系统中除了设置自动居中的高度和宽度之外,还有其他属性吗ImageView是否位于其他ImageView的内部 编辑:它位于RelativeLayout中,图像视图位于左上角,因此我没有添加任何特定于的内容,因为默认情况下它们都在那里 Edit2:

我必须把一个图像视图放在另一个图像视图中。它比较小,必须正好在中心。我对两幅图像都进行了不同屏幕分辨率的缩放,但我只能在一部手机上进行测试,我想知道我是否使用dpi设置了第二幅图像的高度和宽度,以适合我的屏幕分辨率,它是否会在所有屏幕上完美匹配,或者安卓系统中除了设置自动居中的高度和宽度之外,还有其他属性吗ImageView是否位于其他ImageView的内部

编辑:它位于RelativeLayout中,图像视图位于左上角,因此我没有添加任何特定于的内容,因为默认情况下它们都在那里

Edit2:将第一个ImageView更改为RelativeLayout有助于将第二个图像居中,但随后RelativeLayout变大并放大作为背景的图像。有没有办法使相对主义者的形象与其背景一样大?

试试这个:

android:layout_gravity="center"

不能将imageView放在另一个视图中。希望下面的代码对您有所帮助

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/background_image"
        android:gravity="center" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/image_on_center" />

    </LinearLayout>

使用
RelativeLayout
然后使用
android:layout\u centerInParent=“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="match_parent"
android:orientation="vertical" >

  <RelativeLayout
   android:layout_width="250dp"
   android:layout_height="250dp"  >

   <ImageView 
       android:id="@+id/base"
       android:layout_height="250dp"
       android:layout_width="250dp"
       android:src="@drawable/home"
       android:layout_alignParentLeft="true"
       android:layout_alignParentTop="true" />

    <ImageView 
       android:id="@+id/center"
       android:layout_height="150dp"
       android:layout_width="150dp"   
       android:src="@drawable/home"
       android:layout_centerInParent="true"
      android:layout_centerVertical="true"   />
 </RelativeLayout>

</RelativeLayout>


是的,这是可行的,但我需要相对大小与我在所有屏幕上设置为背景的图像一样大,设置宽度和高度以包装内容不起作用。这没有帮助。编辑:行得通,我用错图像了。