在布局上堆叠两个不同大小的不同视图

发布于 2024-12-01 02:05:51 字数 1871 浏览 3 评论 0原文

我一直在寻找这个问题的答案,但提供的解决方案并没有解决我的问题。

我有一个布局,在其中显示一些视图(一些按钮和背景)。为此,我添加了一个自定义控件,我已经扩展了线性布局。该控件很好地显示在布局上方。 我想要做的是添加一个额外的 ImageView,它比这个控件大,但它将位于它的前面。

编辑:抱歉,我希望这能解决问题。

我的活动有一个大型布局(相对),我想在此布局上堆叠两个附加视图\布局,因此最终版本将是附加图片:

在此处输入图像描述

这是我的布局 - 将图像视图堆叠在菜单栏上,而不是在菜单栏上其他的。尝试将 FrameLayout 放在其他地方仍然没有给我想要的结果。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background">
    <RelativeLayout android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="450dip">
        <com.myproject.controls.SearchControl
            android:id="@+id/scSearch" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        />
        <ExpandableListView android:id="@+id/lstItems"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/scSearch"
            android:layout_marginLeft="26dip"
        />
    </RelativeLayout>
    <FrameLayout android:layout_width="fill_parent"
            android:layout_height="fill_parent">
    <com.myproject.controls.MenubarMain
        android:id="@+id/mbMenuBarMain"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
    />
    <ImageView android:src="@drawable/myicon"
                android:layout_width="200dip"
                android:layout_height="200dip"
                />
    </FrameLayout>
</LinearLayout>

I've searched for an answer for this all over but the solutions offered did not solve my problem.

I have a layout where I display some views (a few buttons and a background). To this i've added a custom control i've made extending linear layout. This control is displayed above the layout quite nicely.
What I wish to do is add an additional ImageView which is larger than this control but it will be in front of it.

edited: Sorry, I hope this will clear things up.

I have one large layout (Relative) for my activity, I would like to stack on this layout two additional views\layout so the final version will be the picture attached:

enter image description here

This is my layout - which stacks the imageview right on the menubar, and not over the others. Trying to put the FrameLayout elsewhere still didn't give me the wanted result.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background">
    <RelativeLayout android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="450dip">
        <com.myproject.controls.SearchControl
            android:id="@+id/scSearch" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        />
        <ExpandableListView android:id="@+id/lstItems"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/scSearch"
            android:layout_marginLeft="26dip"
        />
    </RelativeLayout>
    <FrameLayout android:layout_width="fill_parent"
            android:layout_height="fill_parent">
    <com.myproject.controls.MenubarMain
        android:id="@+id/mbMenuBarMain"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
    />
    <ImageView android:src="@drawable/myicon"
                android:layout_width="200dip"
                android:layout_height="200dip"
                />
    </FrameLayout>
</LinearLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日裸衫吸 2024-12-08 02:05:51

不确定这是否有效,因为我是在工作时输入的。但这里的故事的寓意是习惯使用RelativeLayout。您对布局有更多的控制权。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background">
    <com.myproject.controls.MenubarMain
        android:id="@+id/mbMenuBarMain"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
    </com.myproject.controls.MenubarMain>
    <com.myproject.controls.SearchControl
        android:id="@+id/scSearch" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">
    </com.myproject.controls.SearchControl>
    <ExpandableListView android:id="@+id/lstItems"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/scSearch"
        android:layout_above="@id/mbMenuBarMain"
        android:layout_paddingLeft="26dp"/>
    <ImageView android:src="@drawable/myicon"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_alignBottom="@id/mbMenuBarMain"
            android:layout_alignRight="@id/mbMenuBarMain"/>
</RelativeLayout>

Not sure it this will work or not cause I'm typing this up at work. But moral of the story here is get used to using RelativeLayout. You have much more control over your layout.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background">
    <com.myproject.controls.MenubarMain
        android:id="@+id/mbMenuBarMain"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
    </com.myproject.controls.MenubarMain>
    <com.myproject.controls.SearchControl
        android:id="@+id/scSearch" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">
    </com.myproject.controls.SearchControl>
    <ExpandableListView android:id="@+id/lstItems"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/scSearch"
        android:layout_above="@id/mbMenuBarMain"
        android:layout_paddingLeft="26dp"/>
    <ImageView android:src="@drawable/myicon"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_alignBottom="@id/mbMenuBarMain"
            android:layout_alignRight="@id/mbMenuBarMain"/>
</RelativeLayout>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文