0

我正在使用如下表格布局:

<TableLayout android:layout_height="wrap_content"
android:layout_width="fill_parent" android:stretchColumns="1" >

<TableRow android:layout_marginTop="2dp">
<TextView android:text="Email Id" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_marginBottom="5dp"
android:layout_marginLeft="3dp" android:textStyle="bold"
android:textSize="16sp" android:textColor="#000000"
android:layout_weight="2" 
android:background="#e0f7fd"/>

<TextView  android:text="abcedfgh.jklmn@gmail.com"
android:layout_width="0dp" android:layout_height="wrap_content"
android:textColor="#000000" android:layout_marginBottom="5dp"
android:layout_weight="2" android:textSize="15sp"
android:layout_marginLeft="3dp"/>
</TableRow>

</TableLayout>

文本“abcedfgh.jklmn@gmail.com”出现在多行中。我必须根据“abcedfgh.jklmn@gmail.com”文本封面的行数将背景颜色设置为 textview“Email Id”。

例如:如果文本“abcedfgh.jklmn@gmail.com”有两行,我必须将背景颜色设置为两行高度的 textview“Email Id”。

4

2 回答 2

2

有一个选项可以找出行数TextView

int lineCount = textView.getLineCount(); 

说前任:

使用 Runnable 线程来避免异常。

YourTextView.post(new Runnable() {
    @Override
    public void run() {
        int totalLine    = YourTextView.getLineCount();
    }
});
于 2013-11-11T13:52:29.537 回答
1
TextView text = (TextView)findViewByID(R.id.text);
int lineCount = text.getLineCount();

这可能会帮助你..

于 2013-11-11T13:53:35.210 回答