如何在android中的另一个imageview之上放置一个imageview [英] How to place an imageview on top of another imageview in android

查看:51
本文介绍了如何在android中的另一个imageview之上放置一个imageview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我迄今为止尝试过的布局,但没有成功

This is my layout which i tried so far without any success

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white">

 <LinearLayout 
    android:id="@+id/lltest" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_centerHorizontal="true">

        <ImageView 
        android:id="@+id/inside_imageview" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_marginTop="5dip"
        android:layout_marginBottom="5dip"
        android:src="@drawable/frame"/>

</LinearLayout>

 <ImageView 
        android:id="@+id/outside_imageview" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_alignTop="@id/inside_imageview"
        android:scaleType="fitXY"/>
</RelativeLayout>

我真正想要的是将我的outside_imageview 放在inside_imageview 之上,具有精确的高度和宽度...如何通过布局来实现?

What i exactly want is to have my outside_imageview on top of inside_imageview with the exact height and width... How to do it through layout?

推荐答案

    <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="@color/white" >

    <ImageView
        android:id="@+id/inside_imageview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dip"
        android:layout_marginTop="5dip"
        android:src="@drawable/frame" />

      <ImageView
         android:id="@+id/outside_imageview"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignTop="@id/inside_imageview"
         android:layout_alignBottom="@id/inside_imageview"
         android:layout_alignLeft="@id/inside_imageview"
         android:layout_alignRight="@id/inside_imageview"            
         android:scaleType="fitXY" />
  </RelativeLayout>

RelativeLayout 中的 layout_align[Top|Bottom|Left|Right] 属性用于根据它们各自的 x 和 y 值在边距内对齐视图.第二个 ImageView 现在将根据边距与第一个 ImageView 的顶部、底部、左侧和右侧对齐.在对齐中忽略填充.

The layout_align[Top|Bottom|Left|Right] attribute in RelativeLayout is used to align views based on their respective x and y values within the margin. The second ImageView will now be aligned to the top, bottom, left, and right of the first ImageView based on the margins. Padding is ignored in the alignment.

这篇关于如何在android中的另一个imageview之上放置一个imageview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆