Java Code Examples for android.support.v4.view.ViewPager#setLayoutParams()

The following examples show how to use android.support.v4.view.ViewPager#setLayoutParams() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuickReplyListView.java    From imsdk-android with MIT License 6 votes vote down vote up
private void init() {
    setOrientation(VERTICAL);
    viewPager = new ViewPager(context);
    bottomDot = new LinearLayout(context);
    LayoutParams params = new LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    params.weight = 1;
    viewPager.setLayoutParams(params);
    bottomDot.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            Utils.dipToPixels(context, 16)));
    bottomDot.setGravity(Gravity.CENTER);
    bottomDot.setOrientation(HORIZONTAL);
    addView(viewPager);
    addView(bottomDot);
}
 
Example 2
Source File: FaceGridView.java    From imsdk-android with MIT License 6 votes vote down vote up
private void init() {
    setOrientation(VERTICAL);
    viewPager = new ViewPager(context);
    bottomDot = new LinearLayout(context);
    LayoutParams params = new LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    params.weight = 1;
    viewPager.setLayoutParams(params);
    bottomDot.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            Utils.dipToPixels(context, 16)));
    bottomDot.setGravity(Gravity.CENTER);
    bottomDot.setOrientation(HORIZONTAL);
    addView(viewPager);
    addView(bottomDot);
}
 
Example 3
Source File: YayaEmoGridView.java    From sctalk with Apache License 2.0 6 votes vote down vote up
private void initViewPage() {
    setOrientation(VERTICAL);
    _viewPager = new ViewPager(_context);
    _llDot = new LinearLayout(_context);

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
            CommonUtil.getDefaultPannelHeight(_context));
    params.gravity=Gravity.BOTTOM;
    _viewPager.setLayoutParams(params);
    _llDot.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT));
    _llDot.setGravity(Gravity.CENTER);
    _llDot.setOrientation(HORIZONTAL);
    addView(_viewPager);
    addView(_llDot);
}
 
Example 4
Source File: UIImageCarouselView.java    From Auie with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 构造视图并初始化
 */
private void init(){
	mUnit = UEUnit.getInstance(getContext());
	mIndexParams = new LinearLayout.LayoutParams(mUnit.translatePX(indexSize), mUnit.translatePX(indexSize));
	mIndexParams.setMargins(mUnit.translatePX(8), 0, 0, 0);
	mViewPager = new ViewPager(getContext());
	mViewPager.setLayoutParams(new LayoutParams(-1, -1));
	mViewPager.setAdapter(adapter);
	mViewPager.setOnPageChangeListener(mPageChangeListener);
	RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(-2, -2);
	params.addRule(CENTER_HORIZONTAL, RelativeLayout.TRUE);
	params.addRule(ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
	params.setMargins(0, 0, 0, mUnit.translatePX(10));
	mIndexLayout = new LinearLayout(getContext());
	mIndexLayout.setLayoutParams(params);
	indexDefaultDrawable = UEImage.createBackground(Color.parseColor("#FFFFFF"), 50, mUnit.translatePX(6));
	indexSelectDrawable = UEImage.createBackground(Color.parseColor("#EEEEEE"), 255, mUnit.translatePX(6));
	addView(mViewPager);
	addView(mIndexLayout);
}
 
Example 5
Source File: EmoGridView.java    From sctalk with Apache License 2.0 5 votes vote down vote up
private void initViewPage() {
    setOrientation(VERTICAL);
    _viewPager = new ViewPager(_context);
    _llDot = new LinearLayout(_context);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
            CommonUtil.getDefaultPannelHeight(_context));
    params.gravity=Gravity.BOTTOM;
    _viewPager.setLayoutParams(params);
    _llDot.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT));
    _llDot.setGravity(Gravity.CENTER);
    _llDot.setOrientation(HORIZONTAL);
    addView(_viewPager);
    addView(_llDot);
}
 
Example 6
Source File: EmojiBorad.java    From umeng_community_android with MIT License 5 votes vote down vote up
/**
 * create ViewPager view</br>
 * 
 * @return
 */
private ViewPager createVIewpager() {
    ViewPager viewPager = new ViewPager(getContext());
    ViewPager.LayoutParams params = new ViewPager.LayoutParams();
    params.width = android.support.v4.view.ViewPager.LayoutParams.MATCH_PARENT;
    params.height = BOARD_HEIGHT;
    viewPager.setLayoutParams(params);
    viewPager.setPadding(0, 15, 0, 0);
    return viewPager;
}
 
Example 7
Source File: ParallaxContainer.java    From ParallaxSplash with Apache License 2.0 5 votes vote down vote up
/**
 * 指定引导页的所有页面布局文件
 *
 * @param childIds
 */
public void setUp(int... childIds) {
    //根据布局文件数组,初始化所有的Fragment
    fragments = new ArrayList<>();
    for (int i = 0; i < childIds.length; i++) {
        ParallaxFragment f = new ParallaxFragment();
        Bundle args = new Bundle();
        //页面索引
        args.putInt("index", i);
        //Fragment中需要加载的布局文件id
        args.putInt("layoutId", childIds[i]);
        f.setArguments(args);
        fragments.add(f);
    }
    //实例化适配器
    MainActivity activity = (MainActivity) getContext();

    adapter = new ParallaxPagerAdapter(activity.getSupportFragmentManager(), fragments);
    //实例化ViewPager

    ViewPager vp = new ViewPager(getContext());

    vp.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    vp.setId(R.id.parallax_pager);
    //绑定
    vp.setAdapter(adapter);

    addView(vp, 0);
    //在翻页的过程中,不断根据视图的标签中对应的动画参数,改变视图的位置或者透明度
    vp.setOnPageChangeListener(this);


}
 
Example 8
Source File: PanelController.java    From XanderPanel with Apache License 2.0 5 votes vote down vote up
private void applyMenu() {
    mPanelRoot.removeAllViews();
    if (null == actionMenu || actionMenu.size() == 0) {
        return;
    }
    for (int i = actionMenu.size() - 1; i >= 0; i--) {
        actionMenu.getItem(i).setOnMenuItemClickListener(this);
    }
    LayoutInflater inflater = LayoutInflater.from(mContext);
    if (showMenuAsGrid) {
        View view = inflater.inflate(R.layout.xander_panel_menu_gridviewpager, mPanelRoot, false);
        ViewPager viewPager = (ViewPager) view.findViewById(R.id.xander_panel_gridviewpager);
        int row = mPagerGridRow, col = mPagerGridCol;
        if (actionMenu.size() < col) {
            row = 1;
            col = actionMenu.size();
        }
        GridViewPagerAdapter pagerAdapter = new GridViewPagerAdapter(mContext, row, col);
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) viewPager.getLayoutParams();
        int screenWidth = mContext.getResources().getDisplayMetrics().widthPixels;
        params.height = (screenWidth / Math.max(3, col)) * row;
        Log.d("wxy", "params " + params.width + " , " + params.height);
        viewPager.setLayoutParams(params);
        pagerAdapter.setActionMenus(actionMenu, viewPager);
        viewPager.setAdapter(pagerAdapter);
        CirclePageIndicator indicator = (CirclePageIndicator) view.findViewById(R.id.xander_panel_indicator);
        indicator.setViewPager(viewPager);
        mPanelRoot.addView(view);
    } else {
        ListView menuList = (ListView) inflater.inflate(R.layout.xander_panel_menu_list, mPanelRoot, false);
        MenuAdapter menuAdapter = new MenuAdapter(mContext, actionMenu);
        menuList.setAdapter(menuAdapter);
        menuList.setOnItemClickListener(panelItemClickListenr);
        mPanelRoot.addView(menuList);
    }
}
 
Example 9
Source File: ViewPagerPageManager.java    From Paginize with MIT License 5 votes vote down vote up
private void initViewPager(Context context) {
    mViewPager = new ViewPager(context);
    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mViewPager.setLayoutParams(lp);

    mPagerAdapter = new InnerPagePagerAdapter();
    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.setOnPageChangeListener(new InnerPageChangeListener());

    getContainerView().addView(mViewPager);
}
 
Example 10
Source File: FwViewPagerPageManager.java    From Paginize with MIT License 5 votes vote down vote up
private void initViewPager(Context context) {
    mViewPager = new ViewPager(context);
    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mViewPager.setLayoutParams(lp);

    mPagerAdapter = new InnerPagePagerAdapter();
    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.setOnPageChangeListener(new InnerPageChangeListener());

    getContainerView().addView(mViewPager);
}
 
Example 11
Source File: ParallaxContainer.java    From ParallaxPager with MIT License 5 votes vote down vote up
public void setupChildren(LayoutInflater inflater, int... childIds) {
  if (getChildCount() > 0) {
    throw new RuntimeException(
        "setupChildren should only be called once when ParallaxContainer is empty");
  }

  if (childIds.length == 1) {
    int id = childIds[0];
    childIds = new int[2];
    childIds[0] = id;
    childIds[1] = id;
  }

  for (int childId : childIds) {
    inflater.inflate(childId, this);
  }

  // hold pageCount because it will change after we add viewpager
  pageCount = getChildCount();
  for (int i = 0; i < pageCount; i++) {
    View view = getChildAt(i);
    addParallaxView(view, i);
  }

  updateAdapterCount();

  // make view pager with same attributes as container
  viewPager = new ViewPager(getContext());
  viewPager.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
  viewPager.setId(R.id.parallax_pager);
  viewPager.setAdapter(adapter);
  attachOnPageChangeListener(viewPager, this);

  addView(viewPager, 0);
}
 
Example 12
Source File: BannerView.java    From MvpRoute with Apache License 2.0 4 votes vote down vote up
/**
	 * 初始化BannerView  加入ViewPager 加入RadioGroup
	 *
	 * @param context
	 * @param attrs
	 */
	private void init(Context context, AttributeSet attrs) {
		TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.BannerView);

		try {
			isPlayStart = typedArray.getBoolean(R.styleable.BannerView_start_plary, DEFAULAT_PALYER);
			selectTab = typedArray.getResourceId(R.styleable.BannerView_tab_select, 0);
			tabMargin = typedArray.getDimensionPixelSize(R.styleable.BannerView_tab_margin, DEFAULT_MARGIN);
			tabBottomMargin = typedArray.getDimensionPixelSize(R.styleable.BannerView_tab_bottom_margin, DEFAULT_BOOTTOM_MARGIN);
			speed = typedArray.getInt(R.styleable.BannerView_viewpager_speed, DEFAULT_VIEWPAGER_SPEED);
			intervalTime = typedArray.getInt(R.styleable.BannerView_intervalTime, DEFAULT_INTERVATIME);
			tabWidth = typedArray.getDimensionPixelSize(R.styleable.BannerView_tab_width, DEFAULT_TAB_WIDTH);
			tabHeight = typedArray.getDimensionPixelSize(R.styleable.BannerView_tab_height, DEFAULT_TAB_HEIGHT);
//			int type = typedArray.get(R.styleable.BannerView_nav_gravity,);
//			LogUtils.d("type==>" + type);

		} finally {
			typedArray.recycle();
		}

		imgs = new LinkedList<>();
		titles = new LinkedList<>();

		viewpager = new ViewPager(context);
		//设置viewpager的切换时间  默认切换时间为1000 单位毫秒
		setPageChangeDuration(speed);
		//设置viewpager的页面切换监听
		viewpager.addOnPageChangeListener(this);
		viewpager.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
		//添加view
		addView(viewpager);
		//创建指示器控件
		radioGroup = new RadioGroup(context);
		radioGroup.setOrientation(RadioGroup.HORIZONTAL);
		LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
		//设置下方偏移量
		params.setMargins(0, 0, 0, tabBottomMargin);
		//设置相对属性
		params.addRule(RelativeLayout.CENTER_HORIZONTAL);
		params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
		radioGroup.setLayoutParams(params);
		addView(radioGroup);
	}
 
Example 13
Source File: EmojiLayoutParams.java    From Indic-Keyboard with Apache License 2.0 4 votes vote down vote up
public void setPagerProperties(final ViewPager vp) {
    final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) vp.getLayoutParams();
    lp.height = mEmojiKeyboardHeight;
    lp.bottomMargin = mEmojiPagerBottomMargin;
    vp.setLayoutParams(lp);
}
 
Example 14
Source File: UIImagePager.java    From Auie with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 初始化控件
 */
private View createContentView() {
	
	rootContainer = new RelativeLayout(context);
	rootContainer.setBackgroundColor(Color.parseColor("#000000"));
	rootContainer.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
	
	LayoutParams contentParams = new LayoutParams(MATCH_PARENT, WRAP_CONTENT);
	contentParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
	contentContainer = new ViewPager(context);
	contentContainer.setAdapter(imageAdapter);
	contentContainer.setLayoutParams(contentParams);
	contentContainer.setOnPageChangeListener(onPageChangeListener);
	
	LayoutParams params = new LayoutParams(MATCH_PARENT, WRAP_CONTENT);
	params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
	indexContainer = new LinearLayout(context);
	indexContainer.setLayoutParams(params);
	indexContainer.setPadding(0, 0, 0, DP * 20);
	indexContainer.setGravity(Gravity.CENTER);
	indexContainer.setOrientation(LinearLayout.HORIZONTAL);
	
	LayoutParams params2 = new LayoutParams(60 * DP, 32 * DP);
	params2.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
	params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
	params2.setMargins(10 * DP, 0, 0, 10 * DP);
	actionButton = new UIButton(context);
	actionButton.setLayoutParams(params2);
	actionButton.setText("删除");
	actionButton.setTextSize(14);
	actionButton.setVisibility(View.GONE);
	actionButton.setTextColor(Color.WHITE);
	actionButton.setBackgroundColor(Color.RED);
	actionButton.setOnClickListener(onClickListener);
	
	rootContainer.addView(contentContainer);
	rootContainer.addView(indexContainer);
	rootContainer.addView(actionButton);
	
	return rootContainer;
}