LiDaming_and 2013-01-06 05:17 采纳率: 100%
浏览 9785
已采纳

android中如何把一个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"
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 的顶部。如何通过布局实现呢?

  • 写回答

3条回答

  • Curie-87 2013-01-07 03:12
    关注
    <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的空白边缘处上下左右对齐。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch