本文整理汇总了Java中android.support.v4.view.ViewPager.setId方法的典型用法代码示例。如果您正苦于以下问题:Java ViewPager.setId方法的具体用法?Java ViewPager.setId怎么用?Java ViewPager.setId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.ViewPager
的用法示例。
在下文中一共展示了ViewPager.setId方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewPager viewPager = new ViewPager(this);
viewPager.setId(View.generateViewId());
setContentView(viewPager, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
viewPager.setAdapter(new Issue117Adapter(getSupportFragmentManager()));
}
示例2: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ViewPager viewPager = new ViewPager(this);
viewPager.setId(View.generateViewId());
setContentView(viewPager);
viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
}
示例3: onFinishInflate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onFinishInflate() {
super.onFinishInflate();
// 动态配置ViewPager
if (getChildCount() == 1) {
// 如果有一个子控件,就尝试把它当作ViewPager
View child = getChildAt(0);
if (child instanceof ViewPager && child instanceof Pager) {
vpContent = (ViewPager) child;
} else {
throw new IllegalStateException("NavView must has 0 or 1 child that implement 'Pager' interface and exptend 'ViewPager' class at same time.");
}
} else {
// 否则默认创建
vpContent = new TpgViewPager(getContext());
}
// 设置默认Id
if (vpContent.getId() == View.NO_ID) {
vpContent.setId(vpContent.hashCode());
}
//获取控件
View view = LayoutInflater.from(getContext()).inflate(R.layout.widget_nav, this);
vDivider = view.findViewById(R.id.v_divider);
rgTabs = view.findViewById(R.id.rg_tabs);
flContent = view.findViewById(R.id.fl_content);
// 将ViewPager添加到界面
if (null != vpContent) {
ViewUtils.removeFromParent(vpContent);
flContent.addView(vpContent);
}
setNavHeight((int) DensityUtils.px2dp(getContext(), mNavHeight));
//设置整个导航栏的背景。如果同时设置了颜色和图片做背景,以图片为主
rgTabs.setBackgroundColor(mNavBgColor);
if (null != mNavBgImg) {
rgTabs.setBackgroundDrawable(mNavBgImg);
}
if (mNavDividerLineColor == Color.TRANSPARENT) {
//如果颜色透明,就隐藏分割线
vDivider.setVisibility(View.GONE);
} else {
//否则就显示分割线,并设置相应颜色
vDivider.setBackgroundColor(mNavDividerLineColor);
vDivider.setVisibility(View.VISIBLE);
}
//设置是否可滑动
setScrollAble(mScrollAble);
}
示例4: onFinishInflate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
/**
* 当View中所有的子控件均被映射成xml后触发
* 可以在这里获取具体的子控件
*/
@Override
protected void onFinishInflate() {
super.onFinishInflate();
// 动态配置ViewPager
if (getChildCount() == 1) {
// 如果有一个子控件,就尝试把它当作ViewPager
View child = getChildAt(0);
if (child instanceof ViewPager && child instanceof Pager) {
vpContent = (ViewPager) child;
} else {
throw new IllegalStateException("TpgView must has 0 or 1 child that implement 'Pager' interface and exptend 'ViewPager' class at same time.");
}
} else {
// 否则默认创建
vpContent = new TpgViewPager(getContext());
}
// 设置默认Id
if (vpContent.getId() == View.NO_ID) {
vpContent.setId(vpContent.hashCode());
}
View view = LayoutInflater.from(getContext()).inflate(R.layout.widget_tpg, this);
rlTab = view.findViewById(R.id.rl_tab);
tvText = view.findViewById(R.id.tv_text);
tlTabs = view.findViewById(R.id.tl_tabs);
ivExpand = view.findViewById(R.id.iv_expand);
flContent = view.findViewById(R.id.fl_content);
// 将ViewPager添加到界面
if (null != vpContent) {
ViewUtils.removeFromParent(vpContent);
flContent.addView(vpContent);
}
//设置自定义属性值到相应控件上
//设置整个Tab栏的高度和背景颜色
setTabHeight((int) DensityUtils.px2dp(getContext(), mTabHeight));
setTabBgColor(mTabBgColor);
//设置TabLayout的字体颜色、TabMode和TabGravity
setTabTextColor(mTabTextNormalColor, mTabTextSelectedColor);
setTabIndicatorColor(mTabIndicatorColor);
setTabIndicatorHeight((int) DensityUtils.px2dp(getContext(), mTabIndicatorHeight));
setTabMode(mTabMode);
setTabGravity(mTabGravity);
//设置TabLayout左边的TextView
mTextSize = DensityUtils.px2sp(getContext(), mTextSize);
mTextMarginLeft = (int) DensityUtils.px2dp(getContext(), mTextMarginLeft);
mTextMarginRight = (int) DensityUtils.px2dp(getContext(), mTextMarginRight);
setText(mText);
setTextColor(mTextColor);
setTextSize(mTextSize);
setTextVisible(mTextVisible);
setTextMarginLeft(mTextMarginLeft);
setTextMarginRight(mTextMarginRight);
//设置是否显示可扩展图标
setExpandVisible(mExpandVisible);
//设置图标资源
setExpandIcon(mExpandIcon);
//设置是否可滑动
setScrollAble(mScrollAble);
}
示例5: onCreateView
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.d("onCreateView " + this);
View rod = inflater.inflate(R.layout.udsendelser_vandret_skift_frag, container, false);
kanal = App.grunddata.kanalFraKode.get(getArguments().getString(P_KANALKODE));
startudsendelse = App.data.udsendelseFraSlug.get(getArguments().getString(P_UDSENDELSE));
if (startudsendelse == null) { // Fix for https://www.bugsense.com/dashboard/project/cd78aa05/errors/805598045
if (!App.PRODUKTION) { // https://www.bugsense.com/dashboard/project/cd78aa05/errors/822628124
App.langToast("startudsendelse==null for " + kanal);
}
Log.e(new IllegalStateException("startudsendelse==null"));
// Fjern backstak og hop ud
FragmentManager fm = getActivity().getSupportFragmentManager();
fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.indhold_frag, new Kanaler_frag());
ft.addToBackStack(null);
ft.commit();
return rod;
}
Log.d("onCreateView " + this + " viser " + " / " + startudsendelse);
viewPager = (ViewPager) rod.findViewById(R.id.pager);
//noinspection ResourceType
viewPager.setId(123); // TODO hvorfor? fjern eller forklar hvorfor R.id.pager ikke er god nok
pager_title_strip = rod.findViewById(R.id.pager_title_strip);
// Da ViewPager er indlejret i et fragment skal adapteren virke på den indlejrede (child)
// fragmentmanageren - ikke på aktivitens (getFragmentManager)
adapter = new UdsendelserAdapter(getChildFragmentManager());
Datoformater.opdateriDagIMorgenIGårDatoStr(App.serverCurrentTimeMillis());
udsendelser = new ArrayList<Udsendelse>();
udsendelser.add(startudsendelse);
adapter.setListe(udsendelser);
viewPager.setAdapter(adapter);
hentUdsendelser(0);
vispager_title_strip();
viewPager.setOnPageChangeListener(this);
// Nødvendigt fordi underfragmenter har optionsmenu
// - ellers nulstilles optionsmenuen ikke når man hopper ud igen!
setHasOptionsMenu(true);
return rod;
}