- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个包含不同长度文本的简单表格。我在表格行中使用 layout_height=wrap_content
。如果你看到图片,它在下一个元素和前一个元素之间有很大的空间。如果我设置高度,那么在横向查看时空间将保留。我不知道在哪里修复它。我主要使用样式...所以奇怪的是有些能用,有些不能用。
sampleLayout.xml
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:background="@color/form_background"
android:shrinkColumns="*"
android:stretchColumns="*">
<!--Table header-->
<TableRow
style="@style/table_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/th_component"
style="@style/table_header"
android:layout_height="match_parent"
android:layout_weight="2.8"
android:text="@string/tableH_komponen"/>
<TextView
android:id="@+id/th_marks"
style="@style/table_header"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/tableH_markah"/>
<TextView
android:id="@+id/th_demerits"
style="@style/table_header"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:text="@string/tableH_demerit"/>
<TextView
android:id="@+id/th_notes"
style="@style/table_header"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text="@string/tableH_catatan"/>
</TableRow>
<!--Component C1-->
<TableRow
style="@style/table_row"
android:layout_height="wrap_content">
<TextView
style="@style/table_attr"
android:text="@string/c1"/>
<TextView
android:id="@+id/tv_cC1"
style="@style/table_component"
android:text="@string/cC1"
/>
<TextView
android:id="@+id/tv_mc1"
style="@style/table_marks"
android:layout_height="wrap_content"
android:text="@string/_6"/>
<CheckBox
android:id="@+id/checkBox_c1"
style="@style/table_demerit"
android:layout_height="wrap_content"/>
<ImageButton
android:id="@+id/btn_c1"
style="@style/table_notes"
android:layout_height="wrap_content"
android:text="@string/catatan"/>
</TableRow>
<!--Component C2-->
<TableRow
style="@style/table_row"
android:layout_height="wrap_content">
<TextView
style="@style/table_attr"
android:text="@string/c2"/>
<TextView
android:id="@+id/tv_cC2"
style="@style/table_headComponent"
android:text="@string/cC2"/>
<ImageButton
android:id="@+id/btn_c2"
style="@style/table_notes"
android:layout_height="wrap_content"
android:text="@string/catatan"/>
</TableRow>
<TableRow
style="@style/table_row"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_cC2_1"
style="@style/table_subComponent"
android:text="@string/cC2_1"/>
<TextView
android:id="@+id/tv_mC2_1"
style="@style/table_marks"
android:layout_height="match_parent"
android:text="@string/_1"/>
<CheckBox
android:id="@+id/checkBox_c2_1"
style="@style/table_subDemerit"
android:layout_height="wrap_content"/>
</TableRow>
<TableRow
style="@style/table_row"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_cC2_2"
style="@style/table_subComponent"
android:layout_height="wrap_content"
android:text="@string/cC2_2"/>
<TextView
android:id="@+id/tv_mC2_2"
style="@style/table_marks"
android:layout_height="wrap_content"
android:text="@string/_1"/>
<CheckBox
android:id="@+id/checkBox_c2_2"
style="@style/table_subDemerit"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
</FrameLayout>
strings.xml
<resources>
<!--Case C-->
<string name="cC1">Pemeriksaan kesihatan ke atas semua pengendali makanan:
\n - Mendapat suntikan pelalian anti-tifoid
\n - Menghadiri Latihan Pengendali Makanan </string>
<string name="cC2">Tahap kebersihan diri yang baik:</string>
<string name="cC2_1">- Berpakaian bersih dan bersesuaian</string>
<string name="cC2_2">- Memakai apron yang bersih dan berpenutup kepala</string>
</resources>
styles.xml
<resources>
<!--kpkt table header-->
<style name="table_header">
<item name="android:textSize">@dimen/textSize_subheading</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/table_textcolor</item>
<item name="android:background">@color/table_background</item>
<item name="android:padding">@dimen/text_padding</item>
<item name="android:layout_width">0dp</item>
<item name="android:gravity">center</item>
</style>
<!--table style-->
<style name="table_row">
<item name="android:gravity">end</item>
<item name="android:layout_width">0dp</item>
<item name="android:weightSum">5</item>
</style>
<style name="table_attr">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">0.3</item>
<item name="android:gravity">center</item>
</style>
<style name="table_component">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">2.5</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
</style>
<style name="table_marks">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center</item>
<item name="android:padding">8dp</item>
</style>
<style name="table_demerit">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">0.7</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:visibility">visible</item>
</style>
<style name="table_notes">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">0.5</item>
<item name="srcCompat">@drawable/ic_edit</item>
<item name="android:contentDescription">catatan</item>
<!--<item name="android:drawableBottom">@drawable/ic_edit</item>-->
<!--<item name="android:drawableTop">@drawable/ic_edit</item>-->
</style>
<!--kpkt table head component-->
<style name="table_headComponent">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">40dp</item>
<item name="android:padding">@dimen/text_padding</item>
<item name="android:layout_weight">4.2</item>
</style>
<!--kpkt table subcomponent-->
<style name="table_subDemerit">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1.2</item>
<item name="android:visibility">visible</item>
</style>
<style name="table_subComponent">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">40dp</item>
<item name="android:padding">8dp</item>
<item name="android:layout_weight">2.5</item>
</style>
</resources>
最佳答案
我可以建议您了解 wrap_content 和 match_parent 的概念,以获得更好的解决方案。
我认为您可以使用水平和垂直方向的线性布局。
因为线性布局比表格布局和表格行更灵活,性能更好。
问:什么时候应该使用表格布局和表格行?
Ans:当我们有相似类型的数据,并且我们想在行和列 View 中表示时,我们应该使用表格布局和表格行。
但是如果我们有非线性数据,那么我们不应该使用表格布局和表格行...而且我认为您有非线性数据。
为了更好地理解以非线性形式显示数据,您应该了解线性布局的 weight_sum 和 layout_weight 属性。
关于android - 当表格行中的 layout_height=wrap_content 时内容不换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45584488/
我有带有 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 包装它的内容高度和宽度。它似乎在宽度上做得很好,但高度不环绕。它覆盖了整个屏幕。有人知道为什么吗?
我是一名优秀的程序员,十分优秀!