android - 如何防止relativeLayout随着linearLayout上升
问题描述
我需要将图标保留在屏幕的底角
单击图标时,会显示一个RelativeLayout,但图标会随之上升
印刷
好的
问题:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/icon"
android:layout_width="45dp"
android:layout_height="45dp"
android:src="@mipmap/ic_launcher"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/close"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginStart="35dp"
android:src="@drawable/ic_close"
tools:ignore="ContentDescription" />
</RelativeLayout>
<LinearLayout
android:id="@+id/content"
android:layout_width="400dp"
android:layout_height="250dp"
android:layout_marginStart="50dp"
android:background="#000000"
android:orientation="vertical"
android:visibility="gone">
<!-- TODO -->
</LinearLayout>
</FrameLayout>
解决方案
您有一个FrameLayout
包含 aRelativeLayout
和的父级LinearLayout
。AFrameLayout
只是将布局放在彼此的顶部,尽管子布局可以使用layout_gravity
. 一般来说,当你混合RelativeLayout
和时它会变得有点疯狂LinearLayout
,尽管你可以做到,只要你了解它们将如何协同工作。
有几种方法可以使您的子布局在您的问题中按照您想要的方式运行,但为了使其快速简单,请使用 parentRelativeLayout
而不是FrameLayout
,并让子视图将自己定位在父布局中,其中之一layout_alignXYZ
属性。(见:https ://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams )我希望这会有所帮助。
推荐阅读
- azure - 事件中心 API POST:40103:授权令牌签名无效
- c# - Roslyn 抛出不支持语言“VisualBasic”
- html - flex 容器中元素的宽度取决于最后一个元素中的内容
- c - 是否有可能:一个结构内的函数,它作用于同一结构的数据成员,而不必提供结构的自引用?
- jquery - 使用 Jquery 插件将 HTML 表格和表单数据导出到 Excel
- mobx-state-tree - 有动态类型支持吗?
- python - Python,用于 API 使用的 URI 中的正斜杠
- c++ - 类模板上一个特定函数的未解析外部符号
- angular - Angular 7 - 带有订阅的 observable 的单元测试
- c - 释放一部分 malloc