My problem is different. With the below xml layouts, I am showing viewpager pages fluently in activity. There is no problem in scroll view and also contents shows. But when I am using the same code in fragment in navigation drawer, then scroll bar
showing but contents not showing. Blank page shows.
I used android:fillViewport="true"
. but no result. below is the image.I also used fixed height for scrollview
. but no result.
This is Main layout
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:textColor="#fff"
android:paddingTop="4dp"
android:paddingBottom="4dp" />
</android.support.v4.view.ViewPager>
</LinearLayout>
This is Child layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:clickable="true"
android:focusable="true"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text1"
android:textSize="20sp"/>
</LinearLayout>
</ScrollView>
This is Main java
public class SwipeNav extends Fragment {
private MyPagerAdapter myPagerAdapter;
private ViewPager viewPager;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.nav_swipe, container, false);
myPagerAdapter = new MyPagerAdapter(getChildFragmentManager(),getContext());
viewPager = (ViewPager) rootView.findViewById(R.id.pager);
viewPager.setAdapter(myPagerAdapter);
return rootView;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
}
This is MyPagerAdapter Class
public class MyPagerAdapter extends FragmentStatePagerAdapter {
private Context context;
public MyPagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.context= context;
}
@Override
public Fragment getItem(int i) {
ArrayList<String> listItem = new ArrayList<String>();
SQLiteDatabase sqLiteDatabase = SqliteDatabase.getInstance(context).getWritableDatabase();
Cursor cursor = sqLiteDatabase.rawQuery("SELECT NAME FROM ARATRIKA", new String[]{});
if (cursor.getCount() == 0) {
} else {
while (cursor.moveToNext()) {
listItem.add(cursor.getString(0));
}
}
Object[] mStringArray = listItem.toArray();
Fragment fragment = new AFragment();
Bundle args = new Bundle();
args.putString(AFragment.ARG_OBJECT, (String)mStringArray[i]);
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
////
ArrayList<String> listItem = new ArrayList<>();
SQLiteDatabase sqLiteDatabase = SqliteDatabase.getInstance(context).getWritableDatabase();
Cursor cursor = sqLiteDatabase.rawQuery("SELECT NAME FROM ARATRIKA", new String[]{});
while (cursor.moveToNext()) {
listItem.add(cursor.getString(cursor.getColumnIndex("NAME")));
}
return listItem.size();
}
@Override
public CharSequence getPageTitle(int position) {
//return tabTitleArray[position];
return "OBJECT " + (position + 1);
}
}
My problem is solved. android:hardwareAccelerated in the Manifest was 'true'. I changed to 'false'
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<application android:hardwareAccelerated="false"/>
</manifest>
Anyway Thanks to You All for helping me to solve the problem.