Android:将 ImageView 放置在布局之间的重叠上 [英] Android: Placing ImageView on overlap between layouts

查看:35
本文介绍了Android:将 ImageView 放置在布局之间的重叠上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在两个布局之间的重叠点上放置一个 ImageView.在下图中,我的目标是将 ImageView 放置在白色方块所在的位置.注意:重叠点不一定垂直居中,如下所示

I am trying to place an ImageView on the overlap point between two layouts. In the picture below, my goal would be to place the ImageView where the white square is. NOTE: The overlap point will not necessarily be centered vertically as shown below

这可以在 XML 中实现吗?

Is this possible in XML?

我现在唯一的猜测是在实际代码中执行此操作.

My only guess right now is to do this in the actual code itself.

EDIT 8/3/2016:作为参考,我认为 ConstraintLayouts 可能是这些类型问题的最佳未来解决方案 http://tools.android.com/tech-docs/layout-editor

EDIT 8/3/2016: For reference, I think ConstraintLayouts may be the best future solution for these types of problems http://tools.android.com/tech-docs/layout-editor

推荐答案

这将满足您的需求,使用固定高度的图像或以编程方式计算.

This will do what you want, with either an image of fixed height, or calculated programatically.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/layoutTop"
        android:layout_width="match_parent"
        android:layout_height="200dp" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/layoutBottom"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_alignParentBottom="true"
        android:layout_below="@id/layoutTop" >
    </RelativeLayout>

    <ImageView
        android:id="@+id/overlapImage"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_above="@id/layoutBottom"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="-20dp" <!-- This should be always half the height, can also be calculated and added programtically -->
        android:adjustViewBounds="true"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

这篇关于Android:将 ImageView 放置在布局之间的重叠上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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