本文整理匯總了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;
}