怎么将viewpager和指示器当作一个view
1个回答
展开全部
用到的知识:
1.ViewPager和Fragment的结合;
2.自定义view;
3.绘图。
package com.xspacing.indicator;
import java.util.ArrayList;
import java.util.List;
import com.xspacing.view.CustomIndicator;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class MainActivity extends FragmentActivity implements OnPageChangeListener, OnClickListener {
private ViewPager mViewPager;
private List<Fragment> mDatas;
private CustomIndicator mCustomIndicator;
private TextView main_tv1;
private TextView main_tv2;
private TextView main_tv3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
initDatas();
}
private void initDatas() {
mDatas = new ArrayList<Fragment>();
mDatas.add(new Fragment1());
mDatas.add(new Fragment2());
mDatas.add(new Fragment3());
mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public int getCount() {
1.ViewPager和Fragment的结合;
2.自定义view;
3.绘图。
package com.xspacing.indicator;
import java.util.ArrayList;
import java.util.List;
import com.xspacing.view.CustomIndicator;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class MainActivity extends FragmentActivity implements OnPageChangeListener, OnClickListener {
private ViewPager mViewPager;
private List<Fragment> mDatas;
private CustomIndicator mCustomIndicator;
private TextView main_tv1;
private TextView main_tv2;
private TextView main_tv3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
initDatas();
}
private void initDatas() {
mDatas = new ArrayList<Fragment>();
mDatas.add(new Fragment1());
mDatas.add(new Fragment2());
mDatas.add(new Fragment3());
mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public int getCount() {
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询