2 outdoorsmanm outdoorsmanm 于 2015.05.27 15:44 提问

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 = "";
@Override
public 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.guide0,R.drawable.guide1 , R.drawable.guide2};


public HomeFragementAdapter(FragmentManager fm) {
    super(fm);
    // TODO Auto-generated constructor stub
}

@Override
public int getIconResId(int index) {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public Fragment getItem(int position ) {
    // TODO Auto-generated method stub
    return Circlefragment.newInstance(CONTENT[position % CONTENT.length]);
}

@Override
public 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;
@Override
public 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;
    }
@Override
public 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>

3个回答

stringsdn
stringsdn   2015.05.28 11:24

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

stringsdn
stringsdn 你说的不太明白
2 年多之前 回复
outdoorsmanm
outdoorsmanm 没有用,我设置了,然后没不见那些circle,可是这样设置的话应该还是存在这样的问题,因为 我需要滑动好几次,跟开始的好几层点一样,没有解决根本问题
2 年多之前 回复
outdoorsmanm
outdoorsmanm   2015.05.29 11:23

没有用,我设置了,然后没不见那些circle,可是这样设置的话应该还是存在这样的问题,因为 我需要滑动好几次,跟开始的好几层点一样,没有解决根本问题

stringsdn
stringsdn   2015.05.29 15:16

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"试试

Csdn user default icon
上传中...
上传图片
插入图片