سلام دوستان در لیوت activity_main.xlm استاد linerarlayout استفاده کردن و orientation رو برابر vertical قرار دادن.
حالا سوال من اینجاست که چرا horizontal قرار میدیم حروف داخل viewpager نمایش داده نمیشه و فقط صفحه خالی نمایش داده میشه و وقتی برمیگردونم روی vertical حروف رو نمایش میده. منظورم رو هم با عکس نشون میدم.
<?xml version="1.0" encoding="utf-8"?>
<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="horizontal"
tools:context=".MainActivity">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
سلام احمد جان وقتی از Linear Layout استفاده می کنیم دو حالت داریم یا چینش افقی یا عمودی فرزندانش
اگه شما می خوای هم TabLayout هم ViewPager رو به صورت افقی بچینی یا قرار بدی باید از VErtical استفاده کنی.
اما اگر میخوای که به صورت عمودی کنار هم بچینی از Horizontal استفاده می کنی.
یه نکته هم هست بحث وزن داخل Linear Layout هستش
فرض کن ما دو فرزند داخلش داریم به اسم TabLayout و ViewPager میتونی به هر کدوم از فرزند ها وزن بدی مثلا بگی ViewPager 70 درصد صفحه رو پر کنه و اون یکی مابقی فضا رو.
Vertically
View1
View2
View3
View4
etc...
Horozontal
View1 View2 View3 View4 etc...
اینم عکس حالت دوم
<?xml version="1.0" encoding="utf-8"?>
<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=".MainActivity">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>