TableLayout 内的 TableRow 内容超出屏幕

发布于 2024-12-17 22:32:36 字数 1815 浏览 1 评论 0原文

我想这个问题很简单。

问题是:我的 TextView(位于 TableLayout 中的 TableRow 中)脱离了可见屏幕。

屏幕截图应澄清:

yep

我尝试过

        tvValue.setLinksClickable(true);
        tvValue.setEllipsize(TruncateAt.MIDDLE);

1) 未应用截断 2)显然,它们显示了链接,但它们不可点击!

由于它是一个高度动态的事情,我需要在代码中完成所有初始化。 所以,这是代码:

public class StartUp extends Activity {

private TableLayout mTableLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Context appContext = getApplicationContext();

    mTableLayout = new TableLayout(appContext);
    mTableLayout.setBackgroundColor(0xffffffff);

    String[] h = new String[] { "email", "facebook", "youtube" };
    String[] v = new String[] { "[email protected]", "http://www.facebook.com/010101010101010", "http://www.youtube.com/lalala" };

    LayoutParams rowLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

    for (int i = 0; i < h.length; ++i) {
        TableRow row = new TableRow(appContext);
        row.setLayoutParams(rowLayoutParams);

        TextView tvHead = new TextView(appContext);
        tvHead.setTextColor(0xff336699);
        tvHead.setPadding(0, 0, 10, 0);
        tvHead.setText(h[i]);

        TextView tvValue = new TextView(appContext);
        tvValue.setTextColor(0xff191919);
        tvValue.setLinksClickable(true);
        tvValue.setText(v[i]);
        tvValue.setEllipsize(TruncateAt.MIDDLE);


        row.addView(tvHead);
        row.addView(tvValue);
        mTableLayout.addView(row);
    }

    setContentView(mTableLayout);

}

}

This problem is pretty simple, I think.

The thing is: My TextView (Which is in a TableRow which is in a TableLayout) gets out of the visible screen.

A screenshot should clarify:

yep

I tried

        tvValue.setLinksClickable(true);
        tvValue.setEllipsize(TruncateAt.MIDDLE);

1) No truncation is applied
2) Obviously, they show links, but they are not clickable!

As its a highly dynamic thing i need to do all initialization in code.
So, here's the code:

public class StartUp extends Activity {

private TableLayout mTableLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Context appContext = getApplicationContext();

    mTableLayout = new TableLayout(appContext);
    mTableLayout.setBackgroundColor(0xffffffff);

    String[] h = new String[] { "email", "facebook", "youtube" };
    String[] v = new String[] { "[email protected]", "http://www.facebook.com/010101010101010", "http://www.youtube.com/lalala" };

    LayoutParams rowLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

    for (int i = 0; i < h.length; ++i) {
        TableRow row = new TableRow(appContext);
        row.setLayoutParams(rowLayoutParams);

        TextView tvHead = new TextView(appContext);
        tvHead.setTextColor(0xff336699);
        tvHead.setPadding(0, 0, 10, 0);
        tvHead.setText(h[i]);

        TextView tvValue = new TextView(appContext);
        tvValue.setTextColor(0xff191919);
        tvValue.setLinksClickable(true);
        tvValue.setText(v[i]);
        tvValue.setEllipsize(TruncateAt.MIDDLE);


        row.addView(tvHead);
        row.addView(tvValue);
        mTableLayout.addView(row);
    }

    setContentView(mTableLayout);

}

}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文