Android:重叠两个视图(有意!) [英] Android: Overlapping two views (intentionally!)

查看:121
本文介绍了Android:重叠两个视图(有意!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道是否可以重叠两个元素?

just wondering is it possible to overlap two elements?

这说明了我正在努力实现的目标:

This is an illustration of what im trying to achieve:

基本上是一个圆形的ImageButton,其中心位于矩形的角上.我应该如何定位它?我可以使用RelativeLayout或其他东西吗?

Basically its a circle ImageButton, which center lies on the corner of a rectangle. How should I go about positioning it? Can I use RelativeLayout or something else?

推荐答案

您可以将RelativeLayout用于蓝色框,将ImageView对准右上角,然后使用负边距将其推到边界框上.这是一个说明一般想法的示例:

You can use a RelativeLayout for the blue box, align your ImageView to the top-right corner, and then use negative margins to push it over the bounding box. Here's a sample illustrating the general idea:

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



    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"        
        android:layout_marginTop="-10dp"
        android:layout_marginRight="-10dp"
        android:src="@drawable/icon"/>
</RelativeLayout>

我玩了更多,并且您必须在RelativeLayout的父级上设置android:clipChildren ="false".这是一个更完整的示例:

I played with this a bit more, and you have to set android:clipChildren="false" on the parent of the RelativeLayout. Here's a more complete sample:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".LoginActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false">
    <RelativeLayout
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#ff0000"
            android:layout_margin="100dp">
        <ImageView
                android:src="@drawable/ic_launcher"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginRight="-25dp"
                android:layout_marginTop="-25dp"/>
    </RelativeLayout>
</LinearLayout>

这篇关于Android:重叠两个视图(有意!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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