如何在android中的另一个imageview之上放置一个imageview
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11959841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to place an imageview on top of another imageview in android
提问by Coder_sLaY
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>
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?
我真正想要的是将我的 outside_imageview 放在具有确切高度和宽度的 inside_imageview 之上......如何通过布局来做到这一点?
回答by DeeV
<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>
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.
的layout_align[Top|Bottom|Left|Right]
在属性RelativeLayout
被用来基于所述内缘各自的x和y值对准意见。第二个ImageView
现在将ImageView
根据边距与第一个的顶部、底部、左侧和右侧对齐。在对齐中忽略填充。
回答by Francesco Vadicamo
FrameLayout
is what you need. You can simply merge the parent layout that is a FrameLayout
too.
Take a look at the Android Developers Blog: http://android-developers.blogspot.it/2009/03/android-layout-tricks-3-optimize-by.html
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>
回答by Michele
You should try a FrameLayout
. Inside a FrameLayout every Child is on top of each other.
你应该尝试一个FrameLayout
. 在 FrameLayout 中,每个 Child 都在彼此之上。
回答by Aditya Vyas-Lakhan
I tried this way and it worked for me,hope it helps
我试过这种方式,它对我有用,希望它有帮助
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dip">
<ImageView
android:id="@+id/image_first"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/imga"/>
<ImageView
android:id="@+id/imageview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/image"/>
</FrameLayout>
回答by Sunil
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/_15dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/_10dp"
android:layout_marginTop="@dimen/_50dp"
android:background="@drawable/white_background"
/>
<ImageView
android:layout_width="@dimen/_100dp"
android:layout_height="@dimen/_100dp"
android:background="@drawable/my_credit"
android:layout_marginTop="@dimen/_5dp"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
回答by Francis Eyogo
I use Elevation only... 0=floor or basement ... lol 1=floor2 10=floor10 the top top
我只使用 Elevation... 0=floor or basement ... lol 1=floor2 10=floor10 the top top
<ImageView
android:id="@+id/blog_user_image_gp"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="70dp"
android:src="@drawable/avatar"
android:scaleType="fitXY"
android:foregroundGravity="center"
android:elevation="10dp"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/users_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:elevation="1dp"
android:scrollbars="vertical" />
回答by MicroRJ
Just add translation z and it will be on top, make sure the translation z is greater than the view you want to be on top of. Sorry for the late response.
只需添加平移 z 它将位于顶部,确保平移 z 大于您想要位于顶部的视图。回复晚了非常抱歉。