列表视图项之间的巨大距离
Huge distance between listview items
我有一个权重总和为 4 的列表视图。包含图像后,我有很大的填充,但我清除了所有边距和填充。通过适配器从 MainActivity 接收所有数据。
下面有屏幕截图和代码。感谢观看和帮助。
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Пн, сегодня"
android:id="@+id/title"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:gravity="center" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/icon"
android:layout_weight="1"
android:src="@drawable/ic_cloud_queue_24dp"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="+17"
android:id="@+id/genre"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="+9"
android:id="@+id/year"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="center_vertical" />
</LinearLayout>
尝试使用此代码。
Changes i have made is added Linear Layout
inside Relative Layout
with match_parent
as Height and Width. Because Linear Layout childs containing match_parent
as height so that will affect the list items. That's why i have added new Root Layout and defined all childs as OP.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/ll1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4">
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center"
android:text="Пн, сегодня"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:id="@+id/icon"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:src="@drawable/ic_dashboard" />
<TextView
android:id="@+id/genre"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center"
android:text="+17"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/year"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center"
android:text="+9"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</RelativeLayout>
LinearLayout
这四个元素的高度为 wrap_content
,这基本上意味着使它成为 children 的高度。但是所有 4 children 的高度都是 match_parent
,这表示刚好适合我的 parent。所以这不是很兼容。我会做的是也给所有 4 children 高度 wrap_content
,或者更好的是给 LinearLayout 一个固定的 layout_height
我有一个权重总和为 4 的列表视图。包含图像后,我有很大的填充,但我清除了所有边距和填充。通过适配器从 MainActivity 接收所有数据。 下面有屏幕截图和代码。感谢观看和帮助。
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Пн, сегодня"
android:id="@+id/title"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:gravity="center" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/icon"
android:layout_weight="1"
android:src="@drawable/ic_cloud_queue_24dp"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="+17"
android:id="@+id/genre"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="+9"
android:id="@+id/year"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="center_vertical" />
</LinearLayout>
尝试使用此代码。
Changes i have made is added
Linear Layout
insideRelative Layout
withmatch_parent
as Height and Width. Because Linear Layout childs containingmatch_parent
as height so that will affect the list items. That's why i have added new Root Layout and defined all childs as OP.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/ll1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4">
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center"
android:text="Пн, сегодня"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:id="@+id/icon"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:src="@drawable/ic_dashboard" />
<TextView
android:id="@+id/genre"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center"
android:text="+17"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/year"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center"
android:text="+9"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</RelativeLayout>
LinearLayout
这四个元素的高度为 wrap_content
,这基本上意味着使它成为 children 的高度。但是所有 4 children 的高度都是 match_parent
,这表示刚好适合我的 parent。所以这不是很兼容。我会做的是也给所有 4 children 高度 wrap_content
,或者更好的是给 LinearLayout 一个固定的 layout_height