本文整理匯總了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));
}