本文整理汇总了Java中android.widget.TextView.setEms方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.setEms方法的具体用法?Java TextView.setEms怎么用?Java TextView.setEms使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TextView
的用法示例。
在下文中一共展示了TextView.setEms方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import android.widget.TextView; //导入方法依赖的package包/类
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);
}
示例2: initView
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 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();
}
}
});
}