开发者

Android :: TextView :: Programitic Creation with setSingleLine(false) - Not wrapping

I'm setting a textview as a child to a TableRow view programmatically and I cannot seem to get the text to wrap inside of the parent.

Here is the code which should be wrapping the text inside of the TableRow. Notice the setSingleLine is being set to false.

            TextView value = new TextView(this);
    ![alt text][1]value.setLayoutParams(new TableRow.LayoutParams(
            LayoutParams.FILL_PARENT开发者_如何学运维,
            LayoutParams.WRAP_CONTENT));

    value.setSingleLine(false);
    value.setEllipsize(TruncateAt.END);
    value.setHorizontallyScrolling(false);

    value.setText(txt);
    value.setTextColor(Color.BLACK);
    value.setTextSize(12);
    value.setTypeface(generalFont);

The documentation doesn't say by setting it to false will make it multiline, it says it will restore it to the defaults.

setSingleLine(boolean singleLine) If true, sets the properties of this field (lines, horizontally scrolling, transformation method) to be for a single-line input; if false, restores these to the default conditions.

Does anybody have a code snippet or URL which points to a multiline TextView being created programmatically?

TEXT IN TEXT VIEW

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus tempus porttitor diam, sit amet rutrum nunc laoreet at. Mauris sit amet tristique e

IMAGE SHOWING THE ISSUE

Android :: TextView :: Programitic Creation with setSingleLine(false) - Not wrapping


The problem ended it being the grand parent (TableLayout). I had to shrink all columns and the text wrapped.

table.setShrinkAllColumns(true);


What you tried the setHorizontallyScrolling (boolean whether) method?

value.setHorizontallyScrolling(false); 

From the documentation:

Sets whether the text should be allowed to be wider than the View is. If false, it will be wrapped to the width of the View.


You have to set the maximum Ems using setMaxEms(int) this will make your TextViews content be only X Ems wide.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜