В моем приложении сейчас есть ошибка. ListView, который находится внутри фрагмента, не отображает все элементы. Вот скриншот:
Он должен считать до 50. Но это только отсчет до 30 (который вырезан).
Вот мой макет строки элемента ListView:
<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
xmlns:tools = "http://schemas.android.com/tools"
android:layout_width = "match_parent"
android:layout_height = "match_parent">
<RelativeLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content">
<TextView
android:id = "@+id/textView_listview_name"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_marginLeft = "@dimen/_16sdp"
android:layout_marginTop = "@dimen/_4sdp"
android:text = "TextView"
android:textAlignment = "center"
android:textSize = "@dimen/_18ssp"
android:gravity = "center"
android:layout_gravity = "center_vertical"
app:layout_constraintStart_toStartOf = "parent"
app:layout_constraintTop_toTopOf = "parent" />
</RelativeLayout>
</RelativeLayout>
А вот мой фрагмент со спискомView:
<?xml version = "1.0" encoding = "utf-8"?>
<FrameLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:tools = "http://schemas.android.com/tools"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
tools:context = ".GeneralFragment">
<ListView
android:id = "@+id/listViewGeneral"
android:layout_width = "match_parent"
android:layout_height = "wrap_content" />
</FrameLayout>
Спасибо :)
Установите внешнюю высоту ReleativeLayout
на wrap_content
.
Вы можете изменить, как показано ниже:
<ListView
android:id = "@+id/listViewGeneral"
android:layout_width = "match_parent"
android:layout_height = "match_parent" /> //notice this line
Во-первых, макет вашего фрагмента должен быть таким:
<?xml version = "1.0" encoding = "utf-8"?>
<FrameLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:tools = "http://schemas.android.com/tools"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
tools:context = ".GeneralFragment">
<ListView
android:id = "@+id/listViewGeneral"
android:layout_width = "match_parent"
android:layout_height = "match_parent" />
</FrameLayout>
А макет вашей строки можно упростить следующим образом:
<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
xmlns:tools = "http://schemas.android.com/tools"
android:layout_width = "match_parent"
android:layout_height = "wrap_content">
<TextView
android:id = "@+id/textView_listview_name"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_marginLeft = "@dimen/_16sdp"
android:layout_marginTop = "@dimen/_4sdp"
android:text = "TextView"
android:textAlignment = "center"
android:textSize = "@dimen/_18ssp"
android:gravity = "center"
android:layout_gravity = "center_vertical"
app:layout_constraintStart_toStartOf = "parent"
app:layout_constraintTop_toTopOf = "parent" />
</RelativeLayout>
Но на мой взгляд, лучше определить точную высоту строки вашего элемента, например 48dp. В этом случае ваш макет будет более предсказуемым.
показать код адаптера