问题描述
- circlepageindicator 显示怪异
为什么显示的是这样,下面的点为什么在上面,而且,为什么有两个点。我得代码如下:public class HomeFragment extends Fragment{
private View view;private ViewPager pager;private CirclePageIndicator circlePageIndicator;private DisplayImageOptions options;private FragmentManager manager;private static final String KEY_CONTENT = """";@Overridepublic void onAttach(Activity activity) { // TODO Auto-generated method stub super.onAttach(activity);}public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); manager = getActivity().getSupportFragmentManager();}public View onCreateView(LayoutInflater inflater ViewGroup container Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreateView(inflater container savedInstanceState); // inflater.inflate(R.layout.allfragment root attachToRoot); view = inflater.inflate(R.layout.homefragment container false); FragmentTransaction transaction = manager.beginTransaction(); Circlefragment circlefragment = new Circlefragment(); transaction.replace(R.id.content_frame circlefragment); transaction.commit(); return view;}
public class HomeFragementAdapter extends FragmentPagerAdapter implements
IconPagerAdapter {private int mCount = CONTENT.length;protected static final int[] CONTENT = new int[] {R.drawable.guide0R.drawable.guide1 R.drawable.guide2};public HomeFragementAdapter(FragmentManager fm) { super(fm); // TODO Auto-generated constructor stub}@Overridepublic int getIconResId(int index) { // TODO Auto-generated method stub return 0;}@Overridepublic Fragment getItem(int position ) { // TODO Auto-generated method stub return Circlefragment.newInstance(CONTENT[position % CONTENT.length]);}@Overridepublic int getCount() { // TODO Auto-generated method stub return mCount;}public void setCount(int count) { if (count > 0 && count <= 10) { mCount = count; notifyDataSetChanged(); }}
}
public class Circlefragment extends Fragment {
private FragmentManager manager;private CirclePageIndicator circlePageIndicator;private ViewPager pager;private View view;private int mContent;@Overridepublic void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); manager = getActivity().getSupportFragmentManager();}public static Circlefragment newInstance(int content) { Circlefragment fragment = new Circlefragment(); fragment.mContent = content ; return fragment; }@Overridepublic View onCreateView(LayoutInflater inflater ViewGroup container Bundle savedInstanceState) { view = inflater.inflate(R.layout.circlefragment container false); circlePageIndicator = (CirclePageIndicator) view.findViewById(R.id.id_indicator); pager = (ViewPager) view.findViewById(R.id.pager); init(); // TODO Auto-generated method stub return view ;}private void init() { // TODO Auto-generated method stub pager.setAdapter(new HomeFragementAdapter(manager)); circlePageIndicator.setViewPager(pager); pager.setBackgroundResource(mContent); pager.setCurrentItem(0);}
}
<?xml version=""1.0"" encoding=""utf-8""?>
android:layout_width=""match_parent""
android:layout_height=""match_parent""
android:orientation=""vertical"" >android:id=""@+id/pager""
android:layout_width=""match_parent""
android:layout_height=""match_parent"" /><com.viewpagerindicator.CirclePageIndicator android:id=""@+id/id_indicator"" android:layout_width=""wrap_content"" android:layout_height=""wrap_content"" android:layout_alignBottom=""@+id/pager"" android:layout_centerHorizontal=""true"" android:padding=""5dip"" android:layout_margin=""5dip"" android:layout_marginBottom=""10dip"" ></com.viewpagerindicator.CirclePageIndicator>
解决方案
android:id=""@+id/id_indicator""
android:layout_width=""wrap_content""
android:layout_height=""wrap_content""
android:layout_alignBottom=""@+id/pager""
android:layout_centerHorizontal=""true""
android:padding=""5dip""
android:layout_margin=""5dip""
android:layout_marginBottom=""10dip"" >
宽度请设置为 macth-parent
解决方案二:
没有用,我设置了,然后没不见那些circle,可是这样设置的话应该还是存在这样的问题,因为 我需要滑动好几次,跟开始的好几层点一样,没有解决根本问题
解决方案三:
android:id=""@+id/id_indicator""
android:layout_width=""wrap_content""
android:layout_height=""wrap_content""
android:layout_alignBottom=""@+id/pager""
android:layout_centerHorizontal=""true""
android:padding=""5dip""
android:gravity = ""center""
android:layout_margin=""5dip""
android:layout_marginBottom=""10dip"" >
宽度请设置为 macth-parent
添加gravity = ""center""试试