- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试选择 ListActivity,类似于用于向启动器屏幕添加快捷方式的选择。我已经滚动了自己的页眉和页脚,我希望它们在屏幕上时“粘”在 View 的顶部和底部。为此,我使用了一个 RelativeLayout,其中页眉设置为停靠在顶部,页脚设置为停靠在底部,列表设置为位于页眉下方和页脚上方。就 Activity 的整体布局而言,这是我所期望的呈现方式。页眉粘在顶部,页脚粘在底部,列表在它们之间滚动。
当我切换到 RelativeLayout 作为我的根时,发生了一件奇怪的事情。请看下面的截图:
我希望我的 Activity 的高度为 wrap_content
,这样表单的高度就和其中显示的内容一样高,但是一旦我切换到 RelativeLayout,它似乎将 Activity 有效地呈现为 fill_parent
,占据整个屏幕,即使内容不符合要求。请注意,没有足够的列表项来填满屏幕,使用 fill_parent
样式,会在列表末尾和页脚之间留下一堆空白。我正在通过样式设置我的高度 - 这与 LinearLayout 一起工作得很好,但现在似乎被忽略了。所以我尝试直接在 RelativeLayout 上对高度进行硬编码,但它仍然不起作用并且仍然呈现为 fill_parent
。
这是我的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/GroupsList"
android:layout_height="wrap_content">
<FrameLayout android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/hdrGroups"
android:layout_alignParentTop="true">
<include layout="@layout/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</include>
</FrameLayout>
<FrameLayout style="@style/MyFooter"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:id="@+id/ftrGroups">
<ImageView style="@style/CloseButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/add"
android:id="@+id/imgGroupsAdd"
android:clickable="true">
</ImageView>
</FrameLayout>
<ListView android:divider="#9f9f9f"
android:id="@+id/android:list"
android:choiceMode="singleChoice"
android:dividerHeight="1dp"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="@id/hdrGroups"
android:layout_above="@id/ftrGroups">
</ListView>
<TextView android:text="@string/browser_no_groups"
style="@style/ListedItemB"
android:id="@+id/android:empty"
android:layout_height="wrap_content"
android:layout_above="@id/ftrGroups"
android:layout_below="@id/hdrGroups"
android:layout_width="fill_parent">
</TextView>
</RelativeLayout>
所有布局都是通过 XML 完成的,...我没有在代码中进行任何布局。如何获得粘性页眉和页脚,同时让整个 Activity 在 wrap_content
模式下的高度表现?除了 RelativeLayout 之外,还有其他方法可以解决这个问题吗?
最佳答案
根据开发者文档,您想要的行为对于相对布局是不可能的;
"Note that you cannot have a circular dependency between the size of the RelativeLayout and the position of its children. For example, you cannot have a RelativeLayout whose height is set to WRAP_CONTENT and a child set to ALIGN_PARENT_BOTTOM."
要解决您的问题,您可以尝试使用线性布局,设置为 wrap_content 并通过代码将最大高度设置为屏幕高度。
您可以按照此处所述获取屏幕高度:get screen height
关于Android RelativeLayout 和 wrap_content 的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5959608/
我有带有 TextView 和 Button 的 LinearLayout。我将 layout_height 属性设置为 wrap_content 但 layout_height 的尺寸要大得多。如果
所以我知道当我不使用 Modifier.height() 就像设置了“WRAP_CONTENT”,但是如果我想将高度的值设置为 WRAP_CONTENT。有没有办法做到这一点? 已经尝试过 Instr
我制作了一个测验应用程序,但我遇到了单选按钮的问题。我创建了一个圆形背景并将其设置为我的单选按钮背景。但是,背景不会随着单选按钮内的文本量而放大。 这是一张图片 我无法发布信誉度低于 10 的图片。
我的理解是 wrap_content 占用的空间与其内容所需的空间一样多。但这不也适用于 TextView 吗? 在下面的布局中,为什么当我将 ID 为 real_status 的 TextView
目前我在另一个 View 中有一个 View (它是一个广告),但是因为我使用的是 MATCH_PARENT,所以宽度是整个屏幕的长度,而我只希望它是广告尺寸。现在 WRAP_CONTENT 解决了这
我想要实现的是 XML(请不要编写代码!!!)来执行此操作: 我不想要下面的 xml,因为它会将我的弹出窗口拖到屏幕顶部 这是我的 XML,但它也不起作用 :( 最佳答案 如果您有
我正在使用自定义布局来显示对话框。这是布局:
大家好,感谢您的帮助。 我在 Android Studio 中有一个项目。 我在垂直 LinearLayout 中使用 ImageView。 这是我的参数; 你可以在下面看到我的图像(红色 bloc
我对 FrameLayout 有疑问。我想创建 FrameLayout,它将具有第一个 child 的高度,第二个 child 将获得父级的高度(本例中为 100dp)。但我得到的是 FrameLay
当 RecyclerView 的 layout_width 为 wrap_content 时,我试图将其居中,但没有成功 当 RecyclerView 被赋予任何确定的 layout_w
我创建了一个自定义背景图片,并想将其用作高度为 wrap_content 的布局的背景。但是,该布局中内容的总高度远小于背景图像的高度。 当我通过 android:background="@drawa
有一个 TableLayout,它有一堆看起来像这样的行: 当前的行为是,如果第一个按钮的文本换行到第二行,按钮的高度会更大。这很好。然而,另一个按钮,如果它没有那么多文本
我正在尝试使用 wrap_content 让我的 Recycler View 在只有几个项目时不占用所有屏幕空间,但这似乎不起作用。有什么问题? 代码: 最
我正在尝试布局一个应该包装其内容的 View ,但它不应比其父宽度小约 100dp。如何使用 RelativeLayout 或其他布局来做到这一点?我现在所拥有的总是会使 View 比其父 View
“wrap_content”在我的按钮中不起作用,它目前看起来像这样: now want ____________ | |
为什么 RelativeLayout 不换行内容?如果我删除最后一个与底部父级对齐的 View ,它就可以工作...
WRAP_CONTENT 应该这样做: Special value for the height or width requested by a View. WRAP_CONTENT means th
我想创建一个 ViewPager,其宽度环绕其内容,并在其父项中水平居中。第一个代码 fragment 使用 LinearLayout 来创建此效果,如第一个屏幕截图所示。第二个代码 fragment
我正在尝试制作我的 ListView 的行,以便单击任何一行都会在适当的位置展开该行并显示额外的选项。我使用行布局(称为 rowView)包含的额外布局(我们称之为 expandView),高度最初设
我试图让 RelativeLayout 包装它的内容高度和宽度。它似乎在宽度上做得很好,但高度不环绕。它覆盖了整个屏幕。有人知道为什么吗?
我是一名优秀的程序员,十分优秀!