TextView中的换行符添加了填充

时间:2011-02-09 07:32:18

标签: java android textview padding

这是我的TextView:

public IconifiedTextView(Context context, IconifiedText aIconifiedText) {
    super(context);

    /*
     * First Icon and the Text to the right (horizontal), not above and
     * below (vertical)
     */
    this.setOrientation(HORIZONTAL);

    mIcon = new ImageView(context);
    mIcon.setImageDrawable(aIconifiedText.getIcon());
    // left, top, right, bottom
    mIcon.setPadding(0, 3, 7, 3); // 5px to the right

    /*
     * At first, add the Icon to ourself (! we are extending LinearLayout)
     */
    addView(mIcon, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));

    mText = new TextView(context);
    mText.setText(aIconifiedText.getText());
    mText.setTextSize(16);
    /* Now the text (after the icon) */
    addView(mText, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));


    mInfo = new TextView(context);
    mInfo.setText(aIconifiedText.getInfo());
    /* Now the Info (below the Text) */
    addView(mInfo, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
}

当我打电话给我的对象时:

this.directoryEntries.add(new IconifiedText(currentFile
                    .getPath(), currentIcon, "\nInfo"));

“\ nInfo”将在稍后被替换。当我运行这个时,我明白了:

d
 Info
data
    Info
dev
   Info
system
      Info

如何摆脱Info左侧的填充,以便它们都从同一个地方开始?

1 个答案:

答案 0 :(得分:0)

this.directoryEntries.add(new IconifiedText(currentFile
                    .getPath(), currentIcon, "\r\nInfo"));