[英]Buttons above Recycler View in Kotlin
在我的項目中,我有 RecyclerView 並嘗試使用 RecycleView 顯示項目。 一切正常,但下面代碼中的按鈕沒有顯示第一個 recyclerview 項目並將其隱藏。 任何幫助表示贊賞。
<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="TestFragment">
<android.support.v7.widget.RecyclerView
android:id="@+id/testrv"
android:layout_width="match_parent"
android:layout_height="563dp">
</android.support.v7.widget.RecyclerView>
<LinearLayout
android:id="@+id/next_prev_button"
android:layout_below="@+id/rv_homepost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:layout_weight="1"
android:gravity="center_vertical">
<Button
android:id="@+id/prev_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:enabled="true"
android:text="Previous" />
<View
android:layout_width="1dp"
android:layout_height="match_parent" />
<Button
android:id="@+id/next_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:enabled="true"
android:text="Next" />
</LinearLayout>
</FrameLayout>
首先是一個建議 - 為回收者視圖定義特定大小不是一個好方法 - 這取決於設備分辨率/尺寸並且可能不適用於所有。 我通常應該在布局視圖之間重新排列它,以便在可用空間之間適應它。
我不確定我是否正確理解了這個問題 - 但是通過在 Android Studio 上查看您的代碼的結果,我相信這是與回收器視圖重疊的按鈕,對嗎?
建議:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/next_prev_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<Button
android:id="@+id/prev_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:enabled="true"
android:text="Previous" />
<View
android:layout_width="1dp"
android:layout_height="match_parent" />
<Button
android:id="@+id/next_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:enabled="true"
android:text="Next" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/testrv"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.