gpt4 book ai didi

Android向viewpager添加了圆形指示器

转载 作者:IT老高 更新时间:2023-10-28 23:33:56 25 4
gpt4 key购买 nike

您好,我创建了一个 View 寻呼机,但有谁知道我如何在页面 View 上显示代表分页的圆圈,我认为它是一个指标,但我不完全确定?

这是迄今为止包含我的 View 寻呼机的代码

public class LevelSelect extends Activity {

private ViewPager awesomePager;
private static int NUM_AWESOME_VIEWS = 10;
private Context cxt;
private AwesomePagerAdapter awesomeAdapter;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_levelselect);
cxt = this;

awesomeAdapter = new AwesomePagerAdapter();
awesomePager = (ViewPager) findViewById(R.id.viewpager);
awesomePager.setAdapter(awesomeAdapter);
}

private class AwesomePagerAdapter extends PagerAdapter{


@Override
public int getCount() {
return NUM_AWESOME_VIEWS;
}


@Override
public Object instantiateItem(View collection, int position) {

LayoutInflater mLayoutInflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View LeagueButtonView = mLayoutInflater.inflate(R.layout.ls_button, null);
Button LeagueButton = (Button) LeagueButtonView.findViewById(R.id.league);
LeagueButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.ls_level_eng1_locked));
((ViewPager) collection).addView(LeagueButtonView,0);

return LeagueButtonView;
}


@Override
public void destroyItem(View collection, int position, Object view) {
((ViewPager) collection).removeView((View) view);
}



@Override
public boolean isViewFromObject(View view, Object object) {
return view==((View)object);
}


@Override
public void finishUpdate(View arg0) {}


@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {}

@Override
public Parcelable saveState() {
return null;
}

@Override
public void startUpdate(View arg0) {}

}

最佳答案

您可以使用 Jake Wharton 的 ViewPagerIndicator 为 ViewPager 中的每个选项卡添加标题或简单的圆圈。

Jake Wharton 在 GitHub 上提供了一堆示例代码,也可以引用usage section在 Jake Wharton 的网站上。

enter image description here

您也可以使用 Greendroid library 的 ViewPager 和 PageIndicator

enter image description here

关于Android向viewpager添加了圆形指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11486218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com