本文整理汇总了Java中android.widget.TextView.getPaint方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.getPaint方法的具体用法?Java TextView.getPaint怎么用?Java TextView.getPaint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TextView
的用法示例。
在下文中一共展示了TextView.getPaint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addTab
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 添加指示器
*
* @param position
* @param title
*/
private void addTab(final int position, CharSequence title) {
TextView tvTab = new TextView(context);
tvTab.setText(title);
tvTab.setTextColor(textColor);
tvTab.setTextSize(textSize);
tvTab.setGravity(Gravity.CENTER);
if(isIndicatorTextBold){
TextPaint tp = tvTab.getPaint();
tp.setFakeBoldText(true);
}
tvTab.setSingleLine();
tvTab.setFocusable(true);
tvTab.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
viewPager.setCurrentItem(position);
}
});
tvTab.setPadding(indicatorMargin, 0, indicatorMargin, 0);
container.addView(tvTab, position, expandedTabLayoutParams);
}
示例2: measureTabLayoutTextWidth
import android.widget.TextView; //导入方法依赖的package包/类
private void measureTabLayoutTextWidth(int position) {
String title = titles.get(position);
TextView titleView = mSlidingTabLayout.getTitleView(position);
TextPaint paint = titleView.getPaint();
float textWidth = paint.measureText(title);
mSlidingTabLayout.setIndicatorWidth(textWidth / 3);
}
示例3: measureTabLayoutTextWidth
import android.widget.TextView; //导入方法依赖的package包/类
public void measureTabLayoutTextWidth(int position) {
String titleName = titles.get(position);
TextView titleView = mSlidingTab.getTitleView(position);
TextPaint paint = titleView.getPaint();
float v = paint.measureText(titleName);
mSlidingTab.setIndicatorWidth(v / 3);
}
示例4: measureTabLayoutTextWidth
import android.widget.TextView; //导入方法依赖的package包/类
private void measureTabLayoutTextWidth(int position) {
String title = titles.get(position);
TextView titleView = mSlidingTabLayout.getTitleView(position);
TextPaint paint = titleView.getPaint();
float textWidth = paint.measureText(title);
mSlidingTabLayout.setIndicatorWidth(textWidth / 3);
}
示例5: measureTabLayoutTextWidth
import android.widget.TextView; //导入方法依赖的package包/类
private void measureTabLayoutTextWidth(int position) {
String title = mTitles.get(position);
TextView titleView = mSlidingTab.getTitleView(position);
TextPaint paint = titleView.getPaint();
float width = paint.measureText(title);
mSlidingTab.setIndicatorWidth(width / 3);
}
示例6: measureTabLayoutTextWidth
import android.widget.TextView; //导入方法依赖的package包/类
private void measureTabLayoutTextWidth(int position) {
String title = mTitles.get(position);
TextView titleView = mSlidingTabLayout.getTitleView(position);
TextPaint paint = titleView.getPaint();
float textWidth = paint.measureText(title);
mSlidingTabLayout.setIndicatorWidth(textWidth / 3);
}
示例7: getStringWidth
import android.widget.TextView; //导入方法依赖的package包/类
public static int getStringWidth(TextView tv, String text) {
Rect bounds = new Rect();
TextPaint paint;
paint = tv.getPaint();
paint.getTextBounds(text, 0, text.length(), bounds);
int width = bounds.width();
return width;
}
示例8: computeMinWidthRequiredForValues
import android.widget.TextView; //导入方法依赖的package包/类
/**
* Computes and records the minimum width required to display any of the values without
* causing another layout pass when switching values.
*/
int computeMinWidthRequiredForValues() {
DualControlLayout layout = getView(0, null, null);
TextView container = (TextView) layout.getChildAt(1);
Paint textPaint = container.getPaint();
float longestLanguageWidth = 0;
for (int i = 0; i < getCount(); i++) {
float width = textPaint.measureText(getItem(i).toString());
longestLanguageWidth = Math.max(longestLanguageWidth, width);
}
mMinWidthRequiredForValues = (int) Math.ceil(longestLanguageWidth);
return mMinWidthRequiredForValues;
}
示例9: isOverFlowed
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 判断TextView的内容宽度是否超出其可用宽度
*
* @param tv
* @return
*/
public static boolean isOverFlowed(TextView tv, int maxWidth) {
int availableWidth = maxWidth - tv.getPaddingLeft() - tv.getPaddingRight();
Paint textViewPaint = tv.getPaint();
float textWidth = textViewPaint.measureText(tv.getText().toString());
if (textWidth > availableWidth) {
return true;
} else {
return false;
}
}
示例10: getRow
import android.widget.TextView; //导入方法依赖的package包/类
/**
*返回 TextView 里面 String 所占的行数
* @param textView
* @param tvWidth textView 在屏幕上显示的宽(也就是 textView 父容器赐予的最大宽)
* @return 行数
*/
public static int getRow(TextView textView,int tvWidth){
TextPaint paint = textView.getPaint();
float len = paint.measureText(textView.getText().toString());
// 行数 = textWidth/控件显示在屏幕上的宽(父容器允许的最大宽度) ;
int width = tvWidth - textView.getPaddingLeft() - textView.getPaddingRight();// 需要去掉每一行的 padding 值
return (int)Math.ceil(len/width);
}
示例11: getTextWidth
import android.widget.TextView; //导入方法依赖的package包/类
private int getTextWidth(TextView textView) {
if (textView == null) {
return 0;
}
Rect bounds = new Rect();
String text = textView.getText().toString();
Paint paint = textView.getPaint();
paint.getTextBounds(text, 0, text.length(), bounds);
int width = bounds.left + bounds.width();
return width;
}
示例12: resizeText
import android.widget.TextView; //导入方法依赖的package包/类
public static void resizeText(TextView textView, int originalTextSize, int minTextSize) {
final Paint paint = textView.getPaint();
final int width = textView.getWidth();
if (width == 0) {
return;
}
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, originalTextSize);
float ratio = width / paint.measureText(textView.getText().toString());
if (ratio <= 1.0f) {
textView.setTextSize(
TypedValue.COMPLEX_UNIT_PX, Math.max(minTextSize, originalTextSize * ratio));
}
}
示例13: setBold
import android.widget.TextView; //导入方法依赖的package包/类
public static void setBold(TextView textView) {
if (textView != null) {
TextPaint paint = textView.getPaint();
paint.setFakeBoldText(true);
}
}
示例14: setFakeBold
import android.widget.TextView; //导入方法依赖的package包/类
public static void setFakeBold(TextView textView, boolean isBold)
{
TextPaint tp = textView.getPaint();
tp.setFakeBoldText(isBold);
}
示例15: onCreate
import android.widget.TextView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Retrieve the content view that renders the map.
setContentView(R.layout.activity_maps);
// Add title
getSupportActionBar().setTitle("Event Details");
// Add Back button
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
if(actionBar != null){
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
// Get intent
Intent intename = getIntent();
// nameString = (String) intename.getSerializableExtra("NAME");
// timeString = (String) intename.getSerializableExtra("TIME");
nameString = "lalala";
timeString = "24:00";
descriptionString = (String) intename.getSerializableExtra("PostText");
lat = (double) intename.getSerializableExtra("LAT");
lng = (double) intename.getSerializableExtra("LNG");
// zipcodeString = (String) intename.getSerializableExtra("ZIPCODE");
// addressString = (String) intename.getSerializableExtra("ADDRESS");
zipcodeString = "02215";
addressString = "PHO";
location = new LatLng(lat, lng);
// Get the SupportMapFragment and request notification
// when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
// Get TextView
name = (TextView) findViewById(R.id.Name);
time = (TextView) findViewById(R.id.Time);
description = (TextView) findViewById(R.id.Description);
// Get Button
mapAppCtrl = (Button) findViewById(R.id.openMap);
mapAppCtrl.setOnClickListener(new MapsMarkerActivity.ButtonClickHandler());
// Set TextView uneditable
name.setKeyListener(null);
time.setKeyListener(null);
description.setKeyListener(null);
// Set TextView size and bold
name.setTextSize(20);
time.setTextSize(10);
TextPaint paint = name.getPaint();
paint.setFakeBoldText(true);
//Set content
name.setText(nameString);
time.setText(timeString);
description.setText(String.format("%s\n%s\n%s", descriptionString, addressString, zipcodeString));
}