Java Code Examples for android.widget.LinearLayout.setGravity()

The following are Jave code examples for showing how to use setGravity() of the android.widget.LinearLayout class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ViewCacheManager   File: MainActivity.java   View Source Code Vote up 6 votes
private View getItemView() {
    LinearLayout mItemLayout = new LinearLayout(this);
    mItemLayout.setGravity(Gravity.CENTER);
    mItemLayout.setOrientation(LinearLayout.VERTICAL);


    ImageView mImageView = new ImageView(this);
    LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(ui_dip2px(50), ui_dip2px(50));
    mImageView.setLayoutParams(mParams);
    mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);


    TextView mTextView = new TextView(this);
    mTextView.setGravity(Gravity.CENTER);
    mTextView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(4)});
    mTextView.setTextColor(Color.BLUE);

    mItemLayout.addView(mImageView);
    mItemLayout.addView(mTextView);


    return mItemLayout;
}
 
Example 2
Project: MedicationReminder   File: SwipeMenuView.java   View Source Code Vote up 6 votes
private void addItem(SwipeMenuItem item, int id) {
	LayoutParams params = new LayoutParams(item.getWidth(),
			LayoutParams.MATCH_PARENT);
	LinearLayout parent = new LinearLayout(getContext());
	parent.setId(id);
	parent.setGravity(Gravity.CENTER);
	parent.setOrientation(LinearLayout.VERTICAL);
	parent.setLayoutParams(params);
	parent.setBackgroundDrawable(item.getBackground());
	parent.setOnClickListener(this);
	addView(parent);

	if (item.getIcon() != null) {
		parent.addView(createIcon(item));
	}
	if (!TextUtils.isEmpty(item.getTitle())) {
		parent.addView(createTitle(item));
	}

}
 
Example 3
Project: AdPlayBanner   File: ScrollerPager.java   View Source Code Vote up 6 votes
/**
 * 初始化数字页码
 */
private void initPageNumber() {
    if (IndicatorManager.getInstance().getIndicatorType() == NUMBER_INDICATOR) {
        mPageNumberLayout = new LinearLayout(getContext());
        mPageNumberLayout.setOrientation(LinearLayout.HORIZONTAL);
        mPageNumberLayout.setGravity(Gravity.CENTER);

        mPageNumberLayout.removeAllViews();

        mNumberViews = new NumberView[mInfos.size()];

        for (int i = 0; i < mInfos.size(); i++) {
            NumberView numberView;
            if (i == mSelectedIndex) {
                numberView = new NumberView(getContext(), NumberView.mNumberViewSelectedColor);
            } else {
                numberView = new NumberView(getContext(), NumberView.mNumberViewNormalColor);
            }
            numberView.setNumber(i + 1);
            mNumberViews[i] = numberView;
            mPageNumberLayout.addView(mNumberViews[i]);
        }
    }
}
 
Example 4
Project: Expandable-Action-Button   File: ExpandableButtonView.java   View Source Code Vote up 6 votes
public void addItem(ButtonItem...items){
    for(ButtonItem item:items) {
        if(!itemList.contains(item)){
            item.setScaleX(0);
            item.setScaleY(0);
            item.setBackgroundColor(Color.TRANSPARENT);
            LinearLayout layout=new LinearLayout(getContext());
            itemList.add(item);
            layout.setGravity(Gravity.CENTER);
            layout.addView(item);
            wrappedItems.add(layout);
        }

    }

}
 
Example 5
Project: TestChat   File: BaseDialog.java   View Source Code Vote up 6 votes
/**
 * 设置编辑列表VIEW
 *
 * @param names 编辑view 的name
 * @return this
 */
public BaseDialog setEditViewsName(List<String> names) {
        if (middleLayout.getChildCount() > 0) {
                middleLayout.removeAllViews();
        }
        for (String name :
                names) {
                TextView textView = new TextView(getContext());
                textView.setText(name);
                EditText editText = new EditText(getContext());
                editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                editText.setHint("请输入" + name);
                editText.setPadding(10, 0, 0, 0);
                editText.setHintTextColor(Color.BLUE);
                LinearLayout child = new LinearLayout(getContext());
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                child.setOrientation(LinearLayout.HORIZONTAL);
                child.setGravity(Gravity.CENTER_VERTICAL);
                child.setLayoutParams(params);
                child.addView(textView);
                child.addView(editText);
                middleLayout.addView(child);
        }
        return this;
}
 
Example 6
Project: letv   File: ListFragment.java   View Source Code Vote up 6 votes
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Context context = getActivity();
    FrameLayout root = new FrameLayout(context);
    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(1);
    pframe.setVisibility(8);
    pframe.setGravity(17);
    pframe.addView(new ProgressBar(context, null, 16842874), new LayoutParams(-2, -2));
    root.addView(pframe, new LayoutParams(-1, -1));
    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);
    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(17);
    lframe.addView(tv, new LayoutParams(-1, -1));
    ListView lv = new ListView(getActivity());
    lv.setId(16908298);
    lv.setDrawSelectorOnTop(false);
    lframe.addView(lv, new LayoutParams(-1, -1));
    root.addView(lframe, new LayoutParams(-1, -1));
    root.setLayoutParams(new LayoutParams(-1, -1));
    return root;
}
 
Example 7
Project: SwipeMenuAndPullToRefresh   File: SMView.java   View Source Code Vote up 6 votes
private void addItem(SwipeMenuItem item, int id) {
	LayoutParams params = new LayoutParams(item.getWidth(),
			LayoutParams.MATCH_PARENT);
	LinearLayout parent = new LinearLayout(getContext());
	parent.setId(id);
	parent.setGravity(Gravity.CENTER);
	parent.setOrientation(LinearLayout.VERTICAL);
	parent.setLayoutParams(params);
	parent.setBackgroundDrawable(item.getBackground());
	parent.setOnClickListener(this);
	addView(parent);

	if (item.getIcon() != null) {
		parent.addView(createIcon(item));
	}
	if (!TextUtils.isEmpty(item.getTitle())) {
		parent.addView(createTitle(item));
	}

}
 
Example 8
Project: CXJPadProject   File: ConfirmPopup.java   View Source Code Vote up 5 votes
/**
     * @see #makeHeaderView()
     * @see #makeCenterView()
     * @see #makeFooterView()
     */
    @Override
    protected final View makeContentView() {
        LinearLayout rootLayout = new LinearLayout(activity);
        rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
        rootLayout.setBackgroundColor(backgroundColor);
        rootLayout.setOrientation(LinearLayout.VERTICAL);
        rootLayout.setGravity(Gravity.CENTER);
        int padding = ConvertUtils.toPx(activity, contentPaddingLefAndRight);
        rootLayout.setPadding(padding, 0, padding, 0);
        rootLayout.setClipToPadding(false);
        View headerView = makeHeaderView();
        //2017-8-10 lyy 调整头部按钮的显示位置到底部
//        if (headerView != null) {
//            rootLayout.addView(headerView);
//        }
//        if (topLineVisible) {
//            View lineView = new View(activity);
//            lineView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, topLineHeightPixels));
//            lineView.setBackgroundColor(topLineColor);
//            rootLayout.addView(lineView);
//        }
        rootLayout.addView(makeCenterView(), new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1.0f));
        View footerView = makeFooterView();
        if (footerView != null) {
            footerView.setPadding(padding, 0, padding, 0);
            rootLayout.addView(footerView);
        }
        if (topLineVisible) {
            View lineView = new View(activity);
            lineView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, topLineHeightPixels));
            lineView.setBackgroundColor(topLineColor);
            rootLayout.addView(lineView);
        }
        if (headerView != null) {
            rootLayout.addView(headerView);
        }
        return rootLayout;
    }
 
Example 9
Project: AndroidOpen   File: OptionPicker.java   View Source Code Vote up 5 votes
@Override
@NonNull
protected View makeCenterView() {
    if (options.size() == 0) {
        throw new IllegalArgumentException("please initial options at first, can't be empty");
    }
    LinearLayout layout = new LinearLayout(activity);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    layout.setGravity(Gravity.CENTER);
    WheelView optionView = new WheelView(activity);
    optionView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
    optionView.setTextSize(textSize);
    optionView.setTextColor(textColorNormal, textColorFocus);
    optionView.setLineVisible(lineVisible);
    optionView.setLineColor(lineColor);
    optionView.setOffset(offset);
    layout.addView(optionView);
    TextView labelView = new TextView(activity);
    labelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
    labelView.setTextColor(textColorFocus);
    labelView.setTextSize(textSize);
    layout.addView(labelView);
    if (!TextUtils.isEmpty(label)) {
        labelView.setText(label);
    }
    if (TextUtils.isEmpty(selectedOption)) {
        optionView.setItems(options);
    } else {
        optionView.setItems(options, selectedOption);
    }
    optionView.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
        @Override
        public void onSelected(boolean isUserScroll, int selectedIndex, String item) {
            selectedOption = item;
        }
    });
    return layout;
}
 
Example 10
Project: open-rmbt   File: RMBTResultPagerAdapter.java   View Source Code Vote up 5 votes
public void addResultListItem(String title, String value, LinearLayout  netLayout) {
	final float scale = activity.getResources().getDisplayMetrics().density;
    final int leftRightItem = Helperfunctions.dpToPx(5, scale);
    final int topBottomItem = Helperfunctions.dpToPx(5, scale);
    final int leftRightDiv = Helperfunctions.dpToPx(0, scale);
    final int topBottomDiv = Helperfunctions.dpToPx(0, scale);
    final int heightDiv = Helperfunctions.dpToPx(1, scale);        
    final int topBottomImg = Helperfunctions.dpToPx(1, scale);
    
    final LinearLayout netItemLayout = new LinearLayout(activity); 
    
    netItemLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT));
    netItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem, topBottomItem);
    
    netItemLayout.setGravity(Gravity.CENTER_VERTICAL);
    
    final TextView itemTitle = new TextView(activity, null, R.style.listResultItemTitle);
    itemTitle.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT, 0.4f));
    itemTitle.setWidth(0);
    itemTitle.setGravity(Gravity.LEFT);
    itemTitle.setText(title);
    
    netItemLayout.addView(itemTitle);
    
    final ImageView itemClassification = new ImageView(activity);
    itemClassification.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT, 0.1f));
    itemClassification.setPadding(0, topBottomImg, 0, topBottomImg);
    
    itemClassification.setImageDrawable(activity.getResources().getDrawable(
            R.drawable.traffic_lights_none));
    netItemLayout.addView(itemClassification);
    
    final TextView itemValue = new TextView(activity, null, R.style.listResultItemValue);
    itemValue.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT, 0.5f));
    itemValue.setWidth(0);
    itemValue.setGravity(Gravity.LEFT);
    itemValue.setText(value);
    
    netItemLayout.addView(itemValue);
    
    netLayout.addView(netItemLayout);
    
    final View divider = new View(activity);
    divider.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, heightDiv,
            1));
    divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv);
    
    divider.setBackgroundResource(R.drawable.bg_trans_light_10);
    
    netLayout.addView(divider);
    
    netLayout.invalidate();
}
 
Example 11
Project: encdroidMC   File: FillTask.java   View Source Code Vote up 5 votes
@Override
protected void onPreExecute() {
	try {//sometime it crash if the user refresh while the list is already being refreshed
		super.onPreExecute();

		// Replace the ListView with a ProgressBar
		mProgBar = new ProgressBar(volumeBrowserActivity, null,android.R.attr.progressBarStyleLarge);

		// Set the layout to fill the screen
		mListView = volumeBrowserActivity.getListView();
		mLayout = (LinearLayout) mListView.getParent();
		if (mLayout==null) return;
		mLayout.setGravity(Gravity.CENTER);
		mLayout.setLayoutParams(new FrameLayout.LayoutParams(
				LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

		// Set the ProgressBar in the center of the layout
		LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		layoutParams.gravity = Gravity.CENTER;
		mProgBar.setLayoutParams(layoutParams);

		// Replace the ListView with the ProgressBar
		mLayout.removeView(mListView);
		mLayout.addView(mProgBar);
		mProgBar.setVisibility(View.VISIBLE);
	} catch (Exception e){
		e.printStackTrace();
	}
}
 
Example 12
Project: weex-3d-map   File: WXRefreshView.java   View Source Code Vote up 5 votes
private void setupViews() {
  linearLayout = new LinearLayout(getContext());
  FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams
                                                                   .MATCH_PARENT,FrameLayout
      .LayoutParams.MATCH_PARENT);
  linearLayout.setOrientation(LinearLayout.VERTICAL);
  linearLayout.setGravity(Gravity.CENTER);
  addView(linearLayout,lp);
}
 
Example 13
Project: Shared-Route   File: NormalListDialog.java   View Source Code Vote up 5 votes
@SuppressWarnings("deprecation")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final DialogMenuItem item = contents.get(position);

    LinearLayout ll_item = new LinearLayout(context);
    ll_item.setOrientation(LinearLayout.HORIZONTAL);
    ll_item.setGravity(Gravity.CENTER_VERTICAL);

    ImageView iv_item = new ImageView(context);
    iv_item.setPadding(0, 0, dp2px(15), 0);
    ll_item.addView(iv_item);

    TextView tv_item = new TextView(context);
    tv_item.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    tv_item.setSingleLine(true);
    tv_item.setTextColor(itemTextColor);
    tv_item.setTextSize(TypedValue.COMPLEX_UNIT_SP, itemTextSize_SP);

    ll_item.addView(tv_item);
    float radius = dp2px(cornerRadius_DP);
    if (isTitleShow) {
        ll_item.setBackgroundDrawable((CornerUtils.listItemSelector(radius, Color.TRANSPARENT, itemPressColor,
                position == contents.size() - 1)));
    } else {
        ll_item.setBackgroundDrawable(CornerUtils.listItemSelector(radius, Color.TRANSPARENT, itemPressColor,
                contents.size(), position));
    }

    int left = item.resId == 0 ? dp2px(18) : dp2px(16);
    int top = dp2px(10);
    int right = 0;
    int bottom = dp2px(10);
    ll_item.setPadding(left + itemExtraLeft, top + itemExtraTop, right + itemExtraRight, bottom + itemExtraBottom);

    iv_item.setImageResource(item.resId);
    tv_item.setText(item.operName);
    iv_item.setVisibility(item.resId == 0 ? View.GONE : View.VISIBLE);

    return ll_item;
}
 
Example 14
Project: MainCalendar   File: ConfirmPopup.java   View Source Code Vote up 5 votes
/**
 * @see #makeHeaderView()
 * @see #makeCenterView()
 * @see #makeFooterView()
 */
@Override
protected final View makeContentView() {
    LinearLayout rootLayout = new LinearLayout(activity);
    rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
    rootLayout.setBackgroundColor(Color.WHITE);
    rootLayout.setOrientation(LinearLayout.VERTICAL);
    rootLayout.setGravity(Gravity.CENTER);
    rootLayout.setPadding(0, 0, 0, 0);
    rootLayout.setClipToPadding(false);
    View headerView = makeHeaderView();
    if (headerView != null) {
        rootLayout.addView(headerView);
    }
    if (topLineVisible) {
        View lineView = new View(activity);
        lineView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, 1));
        lineView.setBackgroundColor(topLineColor);
        rootLayout.addView(lineView);
    }
    rootLayout.addView(makeCenterView(), new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1.0f));
    View footerView = makeFooterView();
    if (footerView != null) {
        rootLayout.addView(footerView);
    }
    return rootLayout;
}
 
Example 15
Project: TitleBarView   File: TitleBarView.java   View Source Code Vote up 5 votes
/**
 * 初始化子View
 *
 * @param context
 */
private void initView(Context context) {
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    LayoutParams dividerParams = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, mDividerHeight);

    mLeftLayout = new LinearLayout(context);
    mCenterLayout = new LinearLayout(context);
    mRightLayout = new LinearLayout(context);
    mStatusView = new View(context);
    mDividerView = new View(context);

    mLeftLayout.setGravity(Gravity.CENTER_VERTICAL);
    mCenterLayout.setOrientation(LinearLayout.VERTICAL);
    mRightLayout.setGravity(Gravity.CENTER_VERTICAL);

    mLeftTv = new TextView(context);
    mLeftTv.setGravity(Gravity.CENTER);
    mLeftTv.setLines(1);

    mTitleMain = new TextView(context);
    mTitleSub = new TextView(context);

    mRightTv = new TextView(context);
    mRightTv.setGravity(Gravity.CENTER);
    mRightTv.setLines(1);

    mLeftLayout.addView(mLeftTv, params);
    mRightLayout.addView(mRightTv, params);
    addView(mLeftLayout, params);//添加左边容器
    addView(mCenterLayout, params);//添加中间容器
    addView(mRightLayout, params);//添加右边容器
    addView(mDividerView, dividerParams);//添加下划线View
    addView(mStatusView);//添加状态栏View
}
 
Example 16
Project: AndroidOpen   File: ConfirmPopup.java   View Source Code Vote up 5 votes
/**
 * @see #makeHeaderView()
 * @see #makeCenterView()
 * @see #makeFooterView()
 */
@Override
protected final View makeContentView() {
    LinearLayout rootLayout = new LinearLayout(activity);
    rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
    rootLayout.setBackgroundColor(Color.WHITE);
    rootLayout.setOrientation(LinearLayout.VERTICAL);
    rootLayout.setGravity(Gravity.CENTER);
    rootLayout.setPadding(0, 0, 0, 0);
    rootLayout.setClipToPadding(false);
    View headerView = makeHeaderView();
    if (headerView != null) {
        rootLayout.addView(headerView);
    }
    if (topLineVisible) {
        View lineView = new View(activity);
        lineView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, 1));
        lineView.setBackgroundColor(topLineColor);
        rootLayout.addView(lineView);
    }
    rootLayout.addView(makeCenterView(), new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1.0f));
    View footerView = makeFooterView();
    if (footerView != null) {
        rootLayout.addView(footerView);
    }
    return rootLayout;
}
 
Example 17
Project: TripleTap   File: SetGameCardView.java   View Source Code Vote up 4 votes
/**
 * Initialize our card with passed in attributes.
 *
 * @param context Context our view is in
 * @param attrs   Attributes passed into the constructor from code or the layout xml
 */
private void init(Context context, AttributeSet attrs) {

    // Get custom attributes
    TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.SetGameCardView);

    // Set some defaults
    mIsChecked = false;
    mIsHighlighted = false;

    try {
        mAspectRatioWidth = attributes.getInt(R.styleable.SetGameCardView_aspectWidth, 2);
        mAspectRatioHeight = attributes.getInt(R.styleable.SetGameCardView_aspectHeight, 3);

        // Defaults to Oval:Red:One:Solid if not set
        mShape = attributes.getInt(R.styleable.SetGameCardView_symbol_shape, 0);
        mColor = attributes.getInt(R.styleable.SetGameCardView_symbol_color, 0);
        mCount = attributes.getInt(R.styleable.SetGameCardView_symbol_count, 0);
        mFill = attributes.getInt(R.styleable.SetGameCardView_symbol_fill, 0);
    } finally {
        attributes.recycle();
    }

    /*
     * Set up 2D array to get the correct drawable based on shape and fill
     * +--------------------------------------------------+
     * | oval_solid     | oval_open     | oval_stripe     |
     * | diamond_solid  | diamond_open  | diamond_stripe  |
     * | squiggle_solid | squiggle_open | squiggle_stripe |
     * +--------------------------------------------------+
     */
    mShapeFill[0][0] = R.drawable.ic_set_icons_emerald_solid;
    mShapeFill[0][1] = R.drawable.ic_set_icons_emerald_open;
    mShapeFill[0][2] = R.drawable.ic_set_icons_emerald_stripe;
    mShapeFill[1][0] = R.drawable.ic_set_icons_diamond_solid;
    mShapeFill[1][1] = R.drawable.ic_set_icons_diamond_open;
    mShapeFill[1][2] = R.drawable.ic_set_icons_diamond_stripe;
    mShapeFill[2][0] = R.drawable.ic_set_icons_pear_solid;
    mShapeFill[2][1] = R.drawable.ic_set_icons_pear_open;
    mShapeFill[2][2] = R.drawable.ic_set_icons_pear_stripe;

    /*
     * Add a LinearLayout to the card's frame layout to hold the symbols
     */
    mLinearLayout = new LinearLayout(mContext);
    mLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    mLinearLayout.setGravity(Gravity.CENTER);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
    );
    mLinearLayout.setLayoutParams(layoutParams);
    this.setCardBackgroundColor(
            ContextCompat.getColor(getContext(), R.color.card_background_normal));
    this.addView(mLinearLayout);

    drawSymbols();
}
 
Example 18
Project: DateScroller   File: DateScroller.java   View Source Code Vote up 4 votes
private void init(Context context) {


        this.setOrientation(LinearLayout.VERTICAL);
        this.setGravity(Gravity.CENTER);
        this.setBackgroundResource(R.color.datescroller_check_border);

        //the content layout
        contentLinearLayout = new LinearLayout(getContext());
        LayoutParams contentParams = new LayoutParams(
                LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        int margin = DateScrollerUitls.dp2px(getContext(), 8);
        contentParams.topMargin = margin;
        contentParams.leftMargin = margin;
        contentParams.rightMargin = margin;
        contentParams.bottomMargin = margin;
        contentLinearLayout.setLayoutParams(contentParams);
        contentLinearLayout.setPadding(0, 0, DateScrollerUitls.dp2px(getContext(), 8), 0);
        contentLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
        contentLinearLayout.setBackgroundResource(R.drawable.shape_datescroller_bg);

        //today layout
        final LinearLayout todayLinearLayout = (LinearLayout) LayoutInflater.from(getContext())
                .inflate(R.layout.item_datescroller, null);
        LayoutParams todayParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        todayLinearLayout.setLayoutParams(todayParams);
        todayLinearLayout.setGravity(Gravity.CENTER);
        tvTodayDayOfWeek = (TextView) todayLinearLayout.findViewById(R.id.item_datescroller_dayOfWeek);
        tvTodayDayOfWeek.setText(getContext().getString(R.string.datescroller_today));
        tvTodayDayOfWeek.setPadding(DateScrollerUitls.dp2px(getContext(), 8), 0, 0, 0);


        //init today dayta
        todayDate = DateScrollerUitls.addDate(getContext(), calendar, 0);
        currentDate = todayDate;
        todayLinearLayout.setBackgroundResource(R.drawable.shape_datescroller_check_today_bg);

        todayLinearLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dateScollerView.setSelected(-1);
                todayLinearLayout.setBackgroundResource(R.drawable.shape_datescroller_check_today_bg);
                currentDate = todayDate;
                if (onItemClickListener != null)
                    onItemClickListener.onItemClick(currentDate);
            }
        });

        //diver
        View vDiver = new View(getContext());
        vDiver.setLayoutParams(new LayoutParams(DateScrollerUitls.dp2px(getContext(), 1), LayoutParams.MATCH_PARENT));
        vDiver.setBackgroundColor(Color.BLACK);


        contentLinearLayout.addView(todayLinearLayout);
        contentLinearLayout.addView(vDiver);

        dateScollerView = new DateScrollerView(getContext(), calendar);
        dateScollerView.setLayoutParams(
                new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        dateScollerView.setOnItemCheckListener(new DateScrollerView.OnItemCheckListener() {
            @Override
            public void onItemSelected(DateScrollerData datedata) {
                currentDate = datedata;
                if (onItemClickListener != null)
                    onItemClickListener.onItemClick(currentDate);
                todayLinearLayout.setBackgroundResource(0);
            }
        });
        contentLinearLayout.addView(dateScollerView);

        addView(contentLinearLayout);


    }
 
Example 19
Project: NeiHanDuanZiTV   File: BGABanner.java   View Source Code Vote up 4 votes
private void initView(Context context) {
    RelativeLayout pointContainerRl = new RelativeLayout(context);
    if (Build.VERSION.SDK_INT >= 16) {
        pointContainerRl.setBackground(mPointContainerBackgroundDrawable);
    } else {
        pointContainerRl.setBackgroundDrawable(mPointContainerBackgroundDrawable);
    }
    pointContainerRl.setPadding(mPointContainerLeftRightPadding, mPointTopBottomMargin, mPointContainerLeftRightPadding, mPointTopBottomMargin);
    LayoutParams pointContainerLp = new LayoutParams(RMP, RWC);
    // 处理圆点在顶部还是底部
    if ((mPointGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.TOP) {
        pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    } else {
        pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    }
    addView(pointContainerRl, pointContainerLp);


    LayoutParams indicatorLp = new LayoutParams(RWC, RWC);
    indicatorLp.addRule(CENTER_VERTICAL);
    if (mIsNumberIndicator) {
        mNumberIndicatorTv = new TextView(context);
        mNumberIndicatorTv.setId(R.id.banner_indicatorId);
        mNumberIndicatorTv.setGravity(Gravity.CENTER_VERTICAL);
        mNumberIndicatorTv.setSingleLine(true);
        mNumberIndicatorTv.setEllipsize(TextUtils.TruncateAt.END);
        mNumberIndicatorTv.setTextColor(mNumberIndicatorTextColor);
        mNumberIndicatorTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mNumberIndicatorTextSize);
        mNumberIndicatorTv.setVisibility(View.INVISIBLE);
        if (mNumberIndicatorBackground != null) {
            if (Build.VERSION.SDK_INT >= 16) {
                mNumberIndicatorTv.setBackground(mNumberIndicatorBackground);
            } else {
                mNumberIndicatorTv.setBackgroundDrawable(mNumberIndicatorBackground);
            }
        }
        pointContainerRl.addView(mNumberIndicatorTv, indicatorLp);
    } else {
        mPointRealContainerLl = new LinearLayout(context);
        mPointRealContainerLl.setId(R.id.banner_indicatorId);
        mPointRealContainerLl.setOrientation(LinearLayout.HORIZONTAL);
        mPointRealContainerLl.setGravity(Gravity.CENTER_VERTICAL);
        pointContainerRl.addView(mPointRealContainerLl, indicatorLp);
    }

    LayoutParams tipLp = new LayoutParams(RMP, RWC);
    tipLp.addRule(CENTER_VERTICAL);
    mTipTv = new TextView(context);
    mTipTv.setGravity(Gravity.CENTER_VERTICAL);
    mTipTv.setSingleLine(true);
    mTipTv.setEllipsize(TextUtils.TruncateAt.END);
    mTipTv.setTextColor(mTipTextColor);
    mTipTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTipTextSize);
    pointContainerRl.addView(mTipTv, tipLp);

    int horizontalGravity = mPointGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    // 处理圆点在左边、右边还是水平居中
    if (horizontalGravity == Gravity.LEFT) {
        indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        tipLp.addRule(RelativeLayout.RIGHT_OF, R.id.banner_indicatorId);
        mTipTv.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    } else if (horizontalGravity == Gravity.RIGHT) {
        indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
    } else {
        indicatorLp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
    }

    showPlaceholder();
}
 
Example 20
Project: ImageSlider   File: TabIndicatorLayout.java   View Source Code Vote up 3 votes
private void initLayout(Context context) {

        setBackgroundColor(Color.TRANSPARENT);

        mTabIndicators = new ArrayList<>();

        mTabIndicatorHolder = new LinearLayout(context);
        mTabIndicatorHolder.setOrientation(LinearLayout.HORIZONTAL);
        mTabIndicatorHolder.setGravity(Gravity.CENTER);
        addView(mTabIndicatorHolder);

        mFloatingTabIndicator = getTabIndicator();
        //mFloatingTabIndicator.setBackgroundResource(R.drawable.tab_indicator_selector);
        addView(mFloatingTabIndicator);


        mFloatingTabIndicator.setSelected(true);


        LayoutParams layoutParams = (LayoutParams) mTabIndicatorHolder.getLayoutParams();
        layoutParams.height = (int) this.getResources().getDimension(R.dimen.indicator_radius);
        layoutParams.width = (int) this.getResources().getDimension(R.dimen.indicator_radius);

        mFloatingTabIndicator.setLayoutParams(layoutParams);

        layoutParams = new LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        mTabIndicatorHolder.setLayoutParams(layoutParams);
    }