如何在android中的另一个imageview上放置一个imageview

Cod*_*LaY 20 android imageview android-layout

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

<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>
Run Code Online (Sandbox Code Playgroud)

我真正想要的是将我的outside_imageview置于inside_imageview之上,具有确切的高度和宽度......如何通过布局进行操作?

Dee*_*eeV 40

    <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>
Run Code Online (Sandbox Code Playgroud)

所述layout_align[Top|Bottom|Left|Right]属性中RelativeLayout使用基于内缘各自的x和y值来对准意见.第二个ImageView现在将ImageView基于边距与第一个的顶部,底部,左侧和右侧对齐.对齐中忽略填充.


Fra*_*amo 19

FrameLayout是你需要的.您可以简单地合并父布局FrameLayout.看看Android开发者博客:http://android-developers.blogspot.it/2009/03/android-layout-tricks-3-optimize-by.html

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center">

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

    <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" />
</merge>
Run Code Online (Sandbox Code Playgroud)

  • 可悲的是,那个问这个问题的人,不理解,甚至不想了解框架布局可以做什么,并且向我们所有人投降.upvoted你们两个人:) (2认同)

Mic*_*ele 6

你应该尝试一下FrameLayout.在FrameLayout内部,每个Child都在彼此之上.