Java Code Examples for android.widget.TextView.setEms()

The following are Jave code examples for showing how to use setEms() of the android.widget.TextView 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: Multi-SwipeToRefreshLayout   File: IndicatorsRefreshHeader.java   View Source Code Vote up 6 votes
private void init(Context context) {
    if (isInEditMode()) return;
    mIndicatorView = new AVLoadingIndicatorView(context);
    mIndicatorView.setIndicatorId(AVLoadingIndicatorView.Pacman);
    mIndicatorView.setIndicatorColor(Color.WHITE);
    mIndicatorView.setId(R.id.left);
    RelativeLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.addRule(CENTER_IN_PARENT);
    addView(mIndicatorView, layoutParams);

    mText = new TextView(context);
    mText.setEms(6);
    mText.setGravity(Gravity.CENTER);
    RelativeLayout.LayoutParams textLayoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    textLayoutParams.addRule(CENTER_IN_PARENT);
    textLayoutParams.addRule(BELOW, mIndicatorView.getId());
    addView(mText, textLayoutParams);
}
 
Example 2
Project: android-project-gallery   File: XPreferenceGreen.java   View Source Code Vote up 4 votes
/**
 * Init view.
 * 
 * @param attrs
 */
private void initView(AttributeSet attrs)
{
	mRootView = (XPreferenceGreen) LayoutInflater.from(mContext).inflate(R.layout.x_preference, this);
	mContainer = (RelativeLayout) mRootView.findViewById(R.id.container);
	
	mTitle = (TextView) mRootView.findViewById(R.id.title);
	mContent = (TextView) mRootView.findViewById(R.id.content);
	mIndicator = (TextView) mRootView.findViewById(R.id.indicator);
	mHintIcons = (LinearLayout) mRootView.findViewById(R.id.hint_icons);
	mRightText = (TextView) mRootView.findViewById(R.id.right_text);
	
	TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.x_preference);
	
	// Dont need more icon default.
	CharSequence label = typedArray.getText(R.styleable.x_preference_label);
	int label_ems = typedArray.getInteger(R.styleable.x_preference_label_ems, 0);
	if (label_ems > 0)
	{
		// 设置TextView的宽度为N个字符的宽度
		mTitle.setEms(label_ems);
	}

	Drawable icon = typedArray.getDrawable(R.styleable.x_preference_wo2b_icon);
	// Drawable indicator = typedArray.getDrawable(R.styleable.x_preference_indicator);
	// <enum name="arrow" value="0" /> as default.
	mState = typedArray.getInt(R.styleable.x_preference_indicator_state, STATE_ARROW);
	// <enum name="one" value="5" /> as default.
	final int position = typedArray.getInt(R.styleable.x_preference_position, 5);
	// show notice or not?
	
	mEnabled = typedArray.getBoolean(R.styleable.x_preference_enabled, true);
	
	setTitle(label);
	setIcon(icon);
	
	setItemIndicator(mState);
	setItemBackground(mContainer, position);
	
	typedArray.recycle();
	
	mContainer.setOnClickListener(new OnClickListener()
	{
		
		@Override
		public void onClick(View v)
		{
			if (mEnabled)
			{
				onPreferenceClick(mRootView, mState);
			}
			else
			{
				//Toast.makeText(mContext, R.string.hint_not_cancle_power, Toast.LENGTH_SHORT).show();
			}
		}
	});
}