如何调整 Android ListView 行高
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23811071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how resize Android ListView row height
提问by Nininea
Listview row height is too big. I designed row item so. This is ListViewItem Layout axml file
Listview 行高太大。我是这样设计行项目的。这是 ListViewItem 布局 axml 文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_style"
android:gravity="center_horizontal"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:text="Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/forecastName"
android:gravity="center_vertical"
android:padding="10px"
android:textColor="@color/black"/>
</LinearLayout>
and this is Listview layout
这是 Listview 布局
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_style"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/forecast"
android:divider="@drawable/separator"
android:dividerHeight="3px" />
</LinearLayout>
When application lunches list view item has some height, it not match textview size. How can i resize row height?
当应用程序午餐列表视图项具有一定高度时,它与文本视图大小不匹配。如何调整行高?
采纳答案by Nininea
The problem was background image size. android:background="@drawable/list_style"
I use image from background. so i changed size of image. thanks.
问题是背景图像大小。android:background="@drawable/list_style"
我使用背景中的图像。所以我改变了图像的大小。谢谢。
回答by Bartosz Ostrowski
You can just simply provide fixed height in row layout XML:
您可以简单地在行布局 XML 中提供固定高度:
android:layout_height="25dp"
One additional remark:Always use dp
(or dip
) instead of px
when setting view dimensions.
附加说明:在设置视图尺寸时始终使用dp
(或dip
) 而不是px
。
回答by Carlos J
Just adding to the previous answers, you can remove android:minWidth
and android:minHeight
to allow the row wrap the text or you can set the height you want.
只需添加到先前的答案,您就可以删除android:minWidth
并android:minHeight
允许行环绕文本,或者您可以设置所需的高度。
Android has a default value for list item height.
Android 有一个默认的列表项高度值。
android:height="?android:attr/listPreferredItemHeight"
回答by Selz
If rows are bigger than expected, that could be due to android:minWidth and android:minHeight. Try to remove those atributes.
如果行比预期的大,那可能是由于 android:minWidth 和 android:minHeight。尝试删除这些属性。
I see that you are setting units in px. It is not recomended to do such a thing. You should use dp instead of px, except for text size. For text size it is recommended to use sp.
我看到您以 px 为单位设置单位。不建议做这样的事情。除了文本大小之外,您应该使用 dp 而不是 px。对于文本大小,建议使用 sp。
Without a screenshot this is all I got. Let me know if this helps.
没有截图这就是我得到的。如果这有帮助,请告诉我。