代码之家  ›  专栏  ›  技术社区  ›  Ahmed I. Elsayed

如何获取其父视图之外的视图的一部分?

  •  -1
  • Ahmed I. Elsayed  · 技术社区  · 7 年前

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

    action_bar.xml 我会给它充气 RelativeLayout wrap_content &宽度 match_parent ,它有齿轮图标和所有其他细节,除了我不能得到一个圆的图片外的一部分 相对布局 喜欢这幅画。

    我试过用边距,但还是出不来 ,的 改为扩展。所以,更多 margin 在图片中的结果在更高的高度 相对布局 . 有什么建议吗?

    <?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 外面的 相对布局

    2 回复  |  直到 7 年前
        1
  •  1
  •   P.Juni    7 年前

    看看这是不是你要找的

    编辑:

    <?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>
    
        2
  •  0
  •   Ahmed I. Elsayed    7 年前

    首先,我遇到了一个问题,我的数据出现在ImageView下面,而不是后面 但是我通过在frameLayout中的relativeLayout之后添加我的数据(listview)来修复它,顺便说一句,谢谢P.Juni的想法 运行良好的XML是

    <?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="wrap_content"
        android:background="@android:color/transparent">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#000">
    
            <ImageButton
                android:id="@+id/gearIcon"
                android:layout_alignParentRight="true"
                android:background="@drawable/ic_launcher_background"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10sp"
                />
        </RelativeLayout>
    
        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
    
        </ListView>
    
        <ImageButton android:id="@+id/imageButton"
            android:background="@drawable/ic_launcher_background"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="60sp"
            android:layout_marginLeft="30sp"
            android:padding="0sp"/>
    </FrameLayout>