Я хочу разместить представление (и, в частности, группу представлений) в конце RecyclerView. Мой контент RecyclerView выходит за пределы высоты дисплея, поэтому я хочу, чтобы после последнего элемента появлялась другая группа просмотра.
Я пробовал два разных подхода, но ни один из них не дал желаемого эффекта. Это:
Попытка 1
<LinearLayout 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"
android:orientation = "vertical"
tools:context = ".StandingsActivity">
<TableLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:stretchColumns = "*">
<TableRow
android:padding = "5dp">
<!-- the table layout appears well above the RecyclerView -->
</TableRow>
</TableLayout>
<!-- also the following view appears well above the RecyclerView-->
<View
android:layout_width = "match_parent"
android:layout_height = "2dip"
android:background = "@color/accent" />
<android.support.v7.widget.RecyclerView
android:id = "@+id/recyclerview_standings"
android:layout_width = "match_parent"
android:layout_height = "0dp"
android:layout_weight = "1"/>
<!-- the view starting from here are fixed at screen bottom-->
<View
android:layout_width = "match_parent"
android:layout_height = "2dip"
android:background = "@color/accent" />
<TextView
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:textStyle = "bold"
android:text = "Legend"/>
<TextView
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:textColor = "@color/accent"
android:textStyle = "italic"
android:text = "@string/standings_table_legend" />
В этой первой попытке последние представления фиксируются в конце экрана, а элементы RecyclerView прокручиваются внутри середины экрана. Не заходя так далеко за пределы экрана.
Попытка 2
<RelativeLayout 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 = ".StandingsActivity">
<TableLayout
android:id = "@+id/table"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:stretchColumns = "*">
<TableRow
android:padding = "5dp">
<!-- the table layout appears well above the RecyclerView -->
</TableRow>
</TableLayout>
<View
android:id = "@+id/view1"
android:layout_width = "match_parent"
android:layout_height = "2dip"
android:layout_alignParentTop = "true"
android:layout_below = "@id/table"
android:background = "@color/colorAccent" />
<LinearLayout
android:id = "@+id/rec_container"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_below = "@id/view1"
android:orientation = "vertical">
<android.support.v7.widget.RecyclerView
android:id = "@+id/recyclerView"
android:scrollbars = "vertical"
android:layout_weight = "1"
android:layout_width = "match_parent"
android:layout_height = "wrap_content" />
</LinearLayout>
<RelativeLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_alignParentBottom = "true"
android:layout_below = "@id/rec_container">
<View
android:id = "@+id/view2"
android:layout_width = "match_parent"
android:layout_height = "2dip"
android:background = "@color/colorAccent" />
<TextView
android:id = "@+id/text1"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@id/view2"
android:text = "Legend"
android:textColor = "@color/colorAccent"/>
<TextView
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_below = "@id/text1"
android:textColor = "@color/colorAccent"
android:textStyle = "italic"
android:text = "@string/standings_table_legend" />
</RelativeLayout>
Во второй попытке вся группа представлений в RecyclerView никогда не отображается, экран заканчивается последним элементом RecyclerView.
Кто-нибудь может подсказать, как решить эту проблему через xml? заранее спасибо
Вы хотите, чтобы ViewGroup отображался под RecyclerView, но этот ViewGroup должен отображаться только тогда, когда отображается последний элемент RecyclerView? Это верно? Тогда вы можете попробовать адаптер NestedScrollView или ГетерогенныйRecyclerView.
Возможный дубликат Android 5.0 - добавить верхний / нижний колонтитул в RecyclerView
Пожалуйста, посмотрите ответ здесь, чтобы добавить нижний колонтитул в ваш RecyclerView - stackoverflow.com/a/31154402/3145960
Я думаю, что вы, вероятно, можете использовать нижнюю часть этого ответа: stackoverflow.com/a/29168617/3390459