TextView 中的换行符添加填充

发布于 2024-10-16 20:19:30 字数 1495 浏览 1 评论 0原文

这是我的 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

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

This is my 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));
}

And when i call the object I have:

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

Where "\nInfo" will be replaced by something later. When i run this, I get this:

d
 Info
data
    Info
dev
   Info
system
      Info

How do i get rid of this padding to the left of Info so they both start at the same place?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残月升风 2024-10-23 20:19:30
this.directoryEntries.add(new IconifiedText(currentFile
                    .getPath(), currentIcon, "\r\nInfo"));
this.directoryEntries.add(new IconifiedText(currentFile
                    .getPath(), currentIcon, "\r\nInfo"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文