[英]Viewpager content not showing in fragment using ScrollView but Scroll bar showing
我的問題不同了。 使用以下xml布局,我在活動中流暢地顯示viewpager頁面。 滾動視圖和內容顯示沒有問題。 但是當我在導航抽屜中的片段中使用相同的代碼時, scroll bar
顯示但內容未顯示。 空白頁面顯示。
我使用了android:fillViewport="true"
。 但沒有結果。 下面是圖像。我也使用固定高度scrollview
。 但沒有結果。
這是主要布局
<?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>
這是兒童布局
<?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>
這是主要的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);
}
}
這是MyPagerAdapter類
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);
}
}
我的問題解決了。 android:在Manifest中的hardwareAccelerated是'true'。 我改為'假'
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<application android:hardwareAccelerated="false"/>
</manifest>
無論如何感謝You All幫助我解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.