- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的观点是这样的:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
/>
</LinearLayout>
它将为 TextView
提供 50dp,并将其余区域提供给 RecyclerView
。但是,如果 RecyclerView
中的项目小于,比如说 1 或 2,那么它应该缩小到它的 subview 的高度,否则就像布局指定的那样。谁能帮忙??
最佳答案
我认为最好的选择是动态更改 Root View 的 LinearLayout.LayoutParams
。当 RecyclerView
的子级数量较少时,将 LinearLayout
参数设置为:
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
layout.setParams(params);
否则,保持原样。
很容易检测 RecyclerView
是否应该被包装。获取LinearLayout高度:
int height = layout.getTop() - layout.getBottom()
如果此高度低于预期的最大高度(屏幕高度或其他预定义值)。
关于android - 重量和 wrap_content 的布局高度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38359938/
我有带有 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 包装它的内容高度和宽度。它似乎在宽度上做得很好,但高度不环绕。它覆盖了整个屏幕。有人知道为什么吗?
我是一名优秀的程序员,十分优秀!