0

Dies ist mein Layout, wo ich Tablayout und ViewPager in der ScrollView hinzufügen.ViewPager funktioniert nicht in ScrollView

EveryThing ist in Ordnung, aber das ViewPager-Fragment zeigt nichts an.

Dies ist mein xml Layout:

<?xml version="1.0" encoding="utf-8"?> 
<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"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="#252525" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/toolbar"> 

     <RelativeLayout 
      android:id="@+id/rel" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <ImageView 
       android:id="@+id/poster" 
       android:layout_width="96dp" 
       android:layout_height="128dp" 
       android:layout_alignParentRight="true" 
       android:layout_margin="8dp" 
       android:background="#eee" 
       android:src="@mipmap/ic_launcher" /> 

      <TextView 
       android:id="@+id/txt_onvan" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignTop="@id/poster" 
       android:layout_marginBottom="8dp" 
       android:layout_toLeftOf="@id/poster" 
       android:text="عنوان" /> 

      <TextView 
       android:id="@+id/txt_sazande" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/txt_onvan" 
       android:layout_marginBottom="8dp" 
       android:layout_toLeftOf="@id/poster" 
       android:text="سازنده" /> 

      <TextView 
       android:id="@+id/txt_nazar" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/txt_sazande" 
       android:layout_toLeftOf="@id/poster" 
       android:text="تعداد نظر" /> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tablayout" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:layout_below="@id/poster" /> 

      <android.support.v4.view.ViewPager 
       android:id="@+id/viewpager" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/tablayout" 
       /> 

     </RelativeLayout> 
    </ScrollView> 
</RelativeLayout> 

und das ist mein ViewPager Adapter:

package ir.dink.cordinatorexample; 

import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.FragmentStatePagerAdapter; 


public class PagerAdapter extends FragmentStatePagerAdapter { 

    //============================================ Constructor 
    public PagerAdapter(FragmentManager fm) { 
     super(fm); 
    } 

    //============================================ GetItem Method() 
    @Override 
    public Fragment getItem(int position) { 
     Fragment frag = null; 
     switch (position) { 
      case 0: 
       frag = new FragmentOne(); 
       break; 
      case 1: 
       frag = new FragmnentTwo(); 
       break; 
     } 
     return frag; 
    } 
    //============================================= GetCount Method() 
    @Override 
    public int getCount() { 
     return 2; 
    } 
    //============================================= GetPageTitle 
    @Override 
    public CharSequence getPageTitle(int position) { 
     String title = ""; 
     switch (position) { 
      case 0: 
       title = "First"; 
       break; 
      case 1: 
       title = "Second"; 
       break; 
     } 
     return title; 
    } 

} 

und das ist Screen Shot von That:

enter image description here

Antwort

3

Sie sollten Fügen Sie android:fillViewport="true" zu Ihrem ScrollView hinzu.

wie folgt aus:

<?xml version="1.0" encoding="utf-8"?> 
<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"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="#252525" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/toolbar" 
     android:fillViewport="true"> 

     <RelativeLayout 
      android:id="@+id/rel" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <ImageView 
       android:id="@+id/poster" 
       android:layout_width="96dp" 
       android:layout_height="128dp" 
       android:layout_alignParentRight="true" 
       android:layout_margin="8dp" 
       android:background="#eee" 
       android:src="@mipmap/ic_launcher" /> 

      <TextView 
       android:id="@+id/txt_onvan" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignTop="@id/poster" 
       android:layout_marginBottom="8dp" 
       android:layout_toLeftOf="@id/poster" 
       android:text="عنوان" /> 

      <TextView 
       android:id="@+id/txt_sazande" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/txt_onvan" 
       android:layout_marginBottom="8dp" 
       android:layout_toLeftOf="@id/poster" 
       android:text="سازنده" /> 

      <TextView 
       android:id="@+id/txt_nazar" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/txt_sazande" 
       android:layout_toLeftOf="@id/poster" 
       android:text="تعداد نظر" /> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tablayout" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:layout_below="@id/poster" /> 

      <android.support.v4.view.ViewPager 
       android:id="@+id/viewpager" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/tablayout" 
       /> 

     </RelativeLayout> 
    </ScrollView> 
</RelativeLayout> 

und Sie können die diese link sehen.

+0

Danke, es hat funktioniert;) – majid

+0

Ihre Begrüßung !! : D –

Verwandte Themen