/** 图片循环 */ private void initViewPager() { ViewGroup.LayoutParams mViewPagerlayoutParams = mViewPager.getLayoutParams(); if (mViewPagerlayoutParams != null) { mViewPagerlayoutParams.width = Misc.getScreenDisplay(this)[0]; mViewPagerlayoutParams.height = (int) (mViewPagerlayoutParams.width); mViewPager.setLayoutParams(mViewPagerlayoutParams); } mViewPager.setAdapter(new ProductDetailPicAdapter2(this, product.getImgList())); mViewPager.setOnPageChangeListener(this); // 设置布局参数 LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); int marginParam = Misc.dip2px(this, 10) / 2; llytPagerPoiner.removeAllViewsInLayout(); for (int i = 0; i < product.getImgList().size(); i++) { // 设置按钮属性 View item = new ImageView(this); item.setBackgroundResource(R.drawable.recommend_gallery); item.setTag(String.valueOf(i)); // item.setOnClickListener(parentActivity); params.setMargins(marginParam, 0, marginParam, 0); params.weight = 1; llytPagerPoiner.addView(item, params); } llytPagerPoiner.getChildAt(0).setBackgroundResource(R.drawable.recommend_gallery_select); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); mSectionsPagerAdapter = new CalculatorPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} /** * Refreshes the listView in the history fragment whenever the user moves to it. * * @param position page index moving to */ @Override public void onPageSelected(int position) { CalculatorPagerAdapter fragmentPagerAdapter = (CalculatorPagerAdapter) mViewPager.getAdapter(); if (position == HISTORY_PAGE_INDEX) ((HistoryFragment) fragmentPagerAdapter.getRegisteredFragment(position)) .refreshHistory(); } @Override public void onPageScrollStateChanged(int state) {} }); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); // Show welcome demo if this is the first launch mSPref = PreferenceManager.getDefaultSharedPreferences(this); if (mSPref.getBoolean(getString(R.string.pref_is_first_launch_key), true)) showWelcomeDemo(); if (!isPro()) { AdView adView = (AdView) findViewById(R.id.main_ad_view); AdRequest adRequest = new AdRequest.Builder().build(); adView.loadAd(adRequest); // Move up viewPager to allow room for adView ((RelativeLayout.LayoutParams) mViewPager.getLayoutParams()) .addRule(RelativeLayout.ABOVE, R.id.main_ad_view); } }
/** 初始化宫格列表ui */ public void afterPlatformListGot() { Context context = getContext(); // 为了更好的ui效果,开启子线程获取平台列表 int pageSize = platformList.length > PAGE_SIZE ? PAGE_SIZE : platformList.length; int lines = pageSize / 3; if (pageSize % 3 > 0) { lines++; } ViewGroup.LayoutParams lp = pager.getLayoutParams(); int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(context, 10); int scrW = getResources().getDisplayMetrics().widthPixels; lp.height = (scrW - dp_10 * 2) * lines / 3; pager.setLayoutParams(lp); PlatformAdapter adapter = new PlatformAdapter(platformList, this); pager.setAdapter(adapter); int pageCount = 0; if (platformList != null) { int size = platformList.length; pageCount = size / PAGE_SIZE; if (size % PAGE_SIZE > 0) { pageCount++; } } points = new ImageView[pageCount]; if (points.length <= 0) { return; } LinearLayout llPoints = new LinearLayout(context); // 如果页面总是超过1,则设置页面指示器 llPoints.setVisibility(pageCount > 1 ? View.VISIBLE : View.GONE); LayoutParams lpLl = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpLl.gravity = Gravity.CENTER_HORIZONTAL; llPoints.setLayoutParams(lpLl); addView(llPoints); int dp_5 = cn.sharesdk.framework.utils.R.dipToPx(context, 5); grayPoint = BitmapFactory.decodeResource(getResources(), R.drawable.gray_point); whitePoint = BitmapFactory.decodeResource(getResources(), R.drawable.white_point); for (int i = 0; i < pageCount; i++) { points[i] = new ImageView(context); points[i].setScaleType(ScaleType.CENTER_INSIDE); points[i].setImageBitmap(grayPoint); LayoutParams lpIv = new LayoutParams(dp_5, dp_5); lpIv.setMargins(dp_5, dp_5, dp_5, 0); points[i].setLayoutParams(lpIv); llPoints.addView(points[i]); } int curPage = pager.getCurrentItem(); points[curPage].setImageBitmap(whitePoint); }
public void updateView() { Event[] hotEvents = DataEngine.getInstance().getHotEventList(); int maxHeight = 0; Resources res = mContext.getResources(); int eventIconSize = res.getDimensionPixelSize(R.dimen.event_img_size); LayoutInflater inflater = LayoutInflater.from(mContext); for (int i = 0; i < hotEvents.length; ++i) { View v = inflater.inflate(R.layout.view_event_list_cell, null); UrlImageView img = (UrlImageView) v.findViewById(R.id.event_img); img.setImageHeight(eventIconSize); img.setImageWidth(eventIconSize); img.setDefaultBitmap(BitmapFactory.decodeResource(res, R.drawable.ic_launcher)); img.setImageFromUrl(hotEvents[i].getImg()); TextView title = (TextView) v.findViewById(R.id.event_title); title.setText(hotEvents[i].getTitle()); TextView author = (TextView) v.findViewById(R.id.event_author); author.setText(res.getString(R.string.tip_event_author, hotEvents[i].getAuthor())); TextView address = (TextView) v.findViewById(R.id.event_address); address.setText(res.getString(R.string.tip_event_address, hotEvents[i].getAddress())); TextView time = (TextView) v.findViewById(R.id.event_time); time.setText(res.getString(R.string.tip_event_time, hotEvents[i].getEventTime())); v.setTag(hotEvents[i].getEventId()); v.setOnClickListener(mPageOnClickListener); mViews.add(v); measureView(v); maxHeight = maxHeight < v.getMeasuredHeight() ? v.getMeasuredHeight() : maxHeight; ImageView circle = new ImageView(mContext); if (0 == i) { circle.setImageResource(R.drawable.dot_selected); } else { circle.setImageResource(R.drawable.dot_none); } circle.setPadding(5, 0, 5, 0); mCircleContainer.addView(circle); } ViewGroup.LayoutParams lp = mViewPager.getLayoutParams(); lp.height = maxHeight; mViewPager.setLayoutParams(lp); mViewPager.setAdapter(new HotPageAdapter()); mViewPager.setOnPageChangeListener(mPageChangeListener); mCategoryGrid.setNumColumns(3); mCategoryGrid.setAdapter(new CategoryGridAdapter()); mCategoryGrid.setVerticalSpacing( mContext.getResources().getDimensionPixelSize(R.dimen.category_vertical_padding)); }
private void getDataView() { float imgWidths = DPIUtil.screen_width; float imgHeight = imgWidths * 284 / 716; ViewGroup.LayoutParams params = viewPager.getLayoutParams(); params.height = Math.round(imgHeight); params.width = Math.round(imgWidths); viewPager.setLayoutParams(params); custemViewPagerAdapter = new CustemViewPagerAdapter(mViewList); viewPager.setAdapter(custemViewPagerAdapter); mRecyclerView.addHeaderView(headView); adapter = new GridViewAdapter(getActivity(), mList, imgWidth); mRecyclerView.setAdapter(adapter); setListener(); initPopupWindow(); getHomeData(); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d("onCreateView " + this); View rod = inflater.inflate(R.layout.drama_og_bog_frag, container, false); karruselAdapter = new KarruselAdapter(getChildFragmentManager()); viewPager = (ViewPager) rod.findViewById(R.id.pager); viewPager.setAdapter(karruselAdapter); viewPager.getLayoutParams().height = billedeHø; // Viewpageren skal fylde præcist ét billede i højden karruselIndikator = (CirclePageIndicator) rod.findViewById(R.id.indicator); karruselIndikator.setViewPager(viewPager); final float density = getResources().getDisplayMetrics().density; karruselIndikator.setRadius(5 * density); karruselIndikator.setPageColor(Color.BLACK); karruselIndikator.setFillColor(App.color.blå); karruselIndikator.setStrokeColor(0); karruselIndikator.setStrokeWidth(0); DRData.instans.dramaOgBog.observatører.add(this); run(); viewPager.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_UP) { App.forgrundstråd.removeCallbacks(skiftTilNæsteIKarrusellen); App.forgrundstråd.postDelayed(skiftTilNæsteIKarrusellen, 10000); } return false; } }); App.forgrundstråd.postDelayed(skiftTilNæsteIKarrusellen, 10000); AQuery aq = new AQuery(rod); listView = (PinnedSectionListView) aq.id(R.id.listView).adapter(listeAdapter).getListView(); listView.setEmptyView(aq.id(R.id.tom).typeface(App.skrift_gibson).getView()); listView.setOnItemClickListener(this); return rod; }
public void setPagerProperties(final ViewPager vp) { final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) vp.getLayoutParams(); lp.height = mEmojiKeyboardHeight; lp.bottomMargin = mEmojiPagerBottomMargin; vp.setLayoutParams(lp); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View mainView = inflater.inflate(R.layout.home_fragment, null); back = (ImageView) mainView.findViewById(R.id.top_view_back); back.setVisibility(View.GONE); title = (TextView) mainView.findViewById(R.id.top_view_text); Resources resource = this.getResources(); String ecmobileStr = resource.getString(R.string.ecmobile); title.setText(ecmobileStr); title_right_button = (LinearLayout) mainView.findViewById(R.id.top_right_button); title_right_button.setVisibility(View.VISIBLE); title_right_button.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { msgModel.unreadCount = 0; headUnreadTextView.setVisibility(View.GONE); Intent intent = new Intent(getActivity(), ShopNotifyActivity.class); startActivity(intent); getActivity().overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); } }); headUnreadTextView = (TextView) mainView.findViewById(R.id.head_unread_num); if (null == dataModel) { dataModel = new HomeModel(getActivity()); dataModel.fetchHotSelling(); dataModel.fetchCategoryGoods(); } if (null == MsgModel.getInstance()) { msgModel = new MsgModel(getActivity()); } else { msgModel = MsgModel.getInstance(); } msgModel.addResponseListener(this); msgModel.getUnreadMessageCount(); if (null == ConfigModel.getInstance()) { ConfigModel configModel = new ConfigModel(getActivity()); configModel.getConfig(); } dataModel.addResponseListener(this); bannerView = (FrameLayout) LayoutInflater.from(getActivity()).inflate(R.layout.banner_scroll_view, null); bannerViewPager = (ViewPager) bannerView.findViewById(R.id.banner_viewpager); LayoutParams params1 = bannerViewPager.getLayoutParams(); params1.width = getDisplayMetricsWidth(); params1.height = (int) (params1.width * 1.0 / 484 * 200); bannerViewPager.setLayoutParams(params1); bannerListView = new ArrayList<View>(); bannerPageAdapter = new Bee_PageAdapter(bannerListView); bannerViewPager.setAdapter(bannerPageAdapter); bannerViewPager.setCurrentItem(0); bannerViewPager.setOnPageChangeListener( new ViewPager.OnPageChangeListener() { private int mPreviousState = ViewPager.SCROLL_STATE_IDLE; @Override public void onPageScrolled(int i, float v, int i2) {} @Override public void onPageSelected(int i) {} @Override public void onPageScrollStateChanged(int state) { // All of this is to inhibit any scrollable container from consuming our touch events as // the user is changing pages if (mPreviousState == ViewPager.SCROLL_STATE_IDLE) { if (state == ViewPager.SCROLL_STATE_DRAGGING) { mTouchTarget = bannerViewPager; } } else { if (state == ViewPager.SCROLL_STATE_IDLE || state == ViewPager.SCROLL_STATE_SETTLING) { mTouchTarget = null; } } mPreviousState = state; } }); mIndicator = (PageIndicator) bannerView.findViewById(R.id.indicator); mIndicator.setViewPager(bannerViewPager); mListView = (MyListView) mainView.findViewById(R.id.home_listview); mListView.addHeaderView(bannerView); mListView.bannerView = bannerView; mListView.setPullLoadEnable(false); mListView.setPullRefreshEnable(true); mListView.setXListViewListener(this, 0); mListView.setRefreshTime(); homeSetAdapter(); ShoppingCartModel shoppingCartModel = new ShoppingCartModel(getActivity()); shoppingCartModel.addResponseListener(this); shoppingCartModel.homeCartList(); return mainView; }