简体   繁体   English

我如何拆分文本视图?

[英]How i can split a textview?

My question in my opinion is basic. 我认为我的问题是基本的。 However i don't find information about that and how i can do this. 但是,我找不到有关此以及如何执行此操作的信息。

It is possible split a textview? 是否可以拆分textview? Put a line in the middle of the textview? 在textview的中间放一行?

      **TextView**
    ________________   
   |                |
   |________________|               
   |                |
   |________________|

Other thing.... Imagine that textview have height=100dip. 另一件事...。想象一下,textview的高度为100dip。 It is possible color only the first 10% of textview? 可能只有textview的前10%是彩色的吗? Color only the first 10dp?? 仅上色10dp?

Anyone can help? 有人可以帮忙吗? Thank you four your time and help. 谢谢您四个的时间和帮助。

First, You can't split a TextView. 首先,您无法拆分TextView。 But you can achieve by setting a right image as android:setDrawableBottom="yourImage" 但是您可以通过将正确的图像设置为android:setDrawableBottom="yourImage"

You are able to customise a View in Android by overrideing the onDraw method of that View . 您可以自定义View通过overrideing在Android中onDraw该方法View

Something you might consider would be: 您可能会考虑的是:

@Override
protected void onDraw(Canvas canvas) {
    // paint a line through the centre
    Paint paint = new Paint();
    canvas.drawLine(0, canvas.getWidth(), canvas.getHeight()/2, 
                    canvas.getHeight()/2, paint);
    super.onDraw(canvas);
}

This would draw a line through the centre of the View (in your case a TextView ). 这将通过View的中心(在您的情况下为TextView )绘制一条线。 You could use the same method for your 10%/90% colouring. 您可以为10%/ 90%的着色使用相同的方法。

Eg. 例如。

@Override
protected void onDraw(Canvas canvas) {
    // paint a region blue
    Paint paint = new Paint();
    paint.setColor(Color.BLUE);//or whatever colour you want
    canvas.drawRect(0, canvas.getHeight()/10, canvas.getWidth(),
                    canvas.getHeight(), paint)
    super.onDraw(canvas);
}

Draw rect takes the arguments: Draw rect采用以下参数:

canvas.drawRect(left, top, right, bottom, paint)

And there are alternatives where you can pass in the actual drawing Rectangle etc. 还有一些替代方法,您可以在其中传递实际的图纸Rectangle等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM