简体   繁体   English

圆角的角的android,而不是圆形背景

[英]rounded view's corners android, NOT round background

I know how to give round borders using XML in Android. 我知道如何在Android中使用XML给出圆形边框。 I thought it would be cool to make the radius of one corner of my textView excessively large. 我认为将textView的一个角的半径过大会很酷。 The problem is, the text keep spilling out. 问题是,文本不断溢出。 Can I make my textview have a TRULY round corner? 我可以让我的textview拥有一个真正的圆角吗? (Not just the background). (不仅是背景)。 If this was CSS this would be so easy. 如果这是CSS,那就太简单了。 I am new to Android. 我是Android新手。

So in terms of CSS, I want to set my overflow to hidden so to speak. 因此,就CSS而言,我想将溢出设置为隐藏。

Please help me. 请帮我。

In short, no. 简而言之,没有。 All Views are rectangular and fit in bounding boxes. 所有视图均为矩形,并适合边界框。

The best way to achieve rounded corners is the way you mention; 达到圆角的最佳方法是您提到的方法。 using a shape drawable with corner radius set as the background to your TextView. 使用可绘制的形状,其拐角半径设置为TextView的背景。

Like ataulm said, all Views are rectangular. 就像ataulm所说的,所有Views都是矩形的。

Create a shape drawable allows you to create a background with rounded corners. 创建可绘制形状允许您创建带有圆角的背景。 You'd have to use padding to make sure the text doesn't clip in certain areas. 您必须使用填充来确保文本在某些区域不会被剪切。

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#ffffffff"/>    

    <stroke android:width="4dp"
        android:color="#ff0000"/>

    <padding android:left="4dp"
         android:top="4dp"
         android:right="4dp"
         android:bottom="4dp"/> 

    <corners android:bottomRightRadius="7dp" 
             android:bottomLeftRadius="7dp" 
             android:topLeftRadius="7dp" 
             android:topRightRadius="7dp"/> 
</shape>

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

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