在一个封闭的线中确定一个点是不是存在以及textView中文字边界的问题

本文介绍了一种通过自定义算法实现的索引绘制方法,该方法将每条线的点作为索引值以便快速查找。此外,还提供了一个自动调整文本视图高度的方法,确保文本能在限定的高度内显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Bitmap lookup = Bitmap.createBitmap(width, height, Bitmap.Config.ALPHA_8); 
// 
//  确保每个路径都有一个索引值
lookup.eraseColor(0xFF000000); 
 
Canvas canvas = new Canvas(lookup); 
Paint paint = new Paint(); 
 
//
paint.setAntiAlias(false); 
paint.setStyle(Paint.Style.FILL); 
 
for(int i=0;i<paths.size();i++) 
    { 
    paint.setColor(i<<24); 
// 颜色的alpha值0xXX000000 
    canvas.drawPath(paths.get(i), paint);  
    } 

 其实呢在标准的api中是没有这个方法可以调用的,只能通过自己的算法实现

这里呢 是在画的每条线的点都作为一个索引值 然后取索引值就可以了

 

2.

public static void autoScaleTextViewTextToHeight(TextView tv) 
{ 
   
final float initSize = tv.getTextSize(); 
   
//get the width of the view's back image (unscaled)....  
   
float minViewHeight; 
   
if(tv.getBackground()!=null) 
   
{ 
      minViewHeight
= tv.getBackground().getIntrinsicHeight(); 
   
} 
   
else 
   
{ 
      minViewHeight
= 10f;//some min. 
   
} 
   
final float maxViewHeight = tv.getHeight() - (tv.getPaddingBottom()+tv.getPaddingTop())-12;// -12 just to be sure 
   
final String s = tv.getText().toString(); 
 
   
//System.out.println(""+tv.getPaddingTop()+"/"+tv.getPaddingBottom()); 
 
   
if(minViewHeight >0 && maxViewHeight >2) 
   
{ 
     
Rect currentBounds = new Rect(); 
      tv
.getPaint().getTextBounds(s, 0, s.length(), currentBounds); 
     
//System.out.println(""+initSize); 
     
//System.out.println(""+maxViewHeight); 
     
//System.out.println(""+(currentBounds.height())); 
 
     
float resultingSize = 1; 
     
while(currentBounds.height() < maxViewHeight) 
     
{ 
        resultingSize
++; 
        tv
.setTextSize(resultingSize); 
 
        tv
.getPaint().getTextBounds(s, 0, s.length(), currentBounds); 
       
//System.out.println(""+(currentBounds.height()+tv.getPaddingBottom()+tv.getPaddingTop())); 
       
//System.out.println("Resulting: "+resultingSize); 
     
} 
     
if(currentBounds.height()>=maxViewHeight) 
     
{ 
       
//just to be sure, reduce the value 
        tv
.setTextSize(resultingSize-1); 
     
} 
   
} 
} 
以上是群里提出的解答方式 我并没有实际测 只是确实可行的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值