Android 在ViewPager中调整RecyclerView
我已将ViewPgaer实现为:Android 在ViewPager中调整RecyclerView,android,android-fragments,android-recyclerview,Android,Android Fragments,Android Recyclerview,我已将ViewPgaer实现为: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.recycle
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvNotes"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<androidx.viewpager.widget.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
我的问题是如何定位RecyclerView(以及任何其他布局)以不覆盖选项卡?在xml文件中为RecyclerView添加大约50dp的页边空白。
另外,根据用户界面的需要调整边距上限值。是否有自动调整的方法?它在任何设备上都能工作吗?你可以通过编程来完成,在这种情况下,似乎不需要这样做。只需使用xml即可。此外,它适用于任何尺寸和密度的设备。若要确认,请在“预览”选项卡中,在多个设备和尺寸上检查您的设计。