首页 > 解决方案 > 如何在其父级之外获取视图的一部分?

问题描述

我试图创建一个像这样的actionBar,“这是一个网站模板”

所以我创建了一个我将膨胀的文件,action_bar.xmlA的RelativeLayout高度为wrap_content& 宽度为.match_parentRelativeLayout

我尝试使用边距,但它并没有脱离 ,RelativeLayout而是RelativeLayout被扩展了。因此,margin图片中的更多会导致RelativeLayout. 有什么建议么?

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

    <ImageButton android:src="@drawable/roundPicture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="30sp"
        android:layout_marginLeft="30sp"
        android:padding="0sp"/>

    <ImageButton
        android:id="@+id/gearIcon"
        android:layout_alignParentRight="true"
        android:background="@drawable/gearICON"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10sp"
        />
</RelativeLayout>

请不要图书馆,我不是在制作应用程序,我只是想理解。

快速回顾一下。我想要第一个ImageButton外面的一部分RelativeLayout

标签: javaandroidandroid-layout

解决方案


检查这是否是您要查找的内容

编辑:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#fff">

    <ImageButton
        android:id="@+id/gearIcon"
        android:layout_alignParentRight="true"
        android:background="@android:drawable/ic_delete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10sp"
        />
</RelativeLayout>
<ImageButton
    android:background="@android:drawable/ic_delete"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_marginTop="30sp"
    android:layout_marginLeft="30sp"
    android:padding="0sp"/>
</FrameLayout>

推荐阅读