android - 以编程方式调整文本大小,文本超出 Viewbounds,修复了吗?

标签 android interface resize textview

我正在尝试根据布局中的行数(布局具有固定高度)调整线性布局中行的大小。这些行应该总是完全填满父布局。所以 1 行是父级的全尺寸,2 行都是尺寸的一半等。 这行得通,我现在也在尝试调整文本的大小,但是当我调整它的大小时它被切断了,即使 textview 足够大(我打开了果冻 bean 的显示 View 边界功能)

private void setHeightOfRows(ViewGroup parent) {
    int height = parent.getHeight();
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        LinearLayout.LayoutParams p = (LayoutParams) parent.getChildAt(i).getLayoutParams();
        p.height = height / childCount;
        parent.getChildAt(i).setLayoutParams(p);
        ((ViewGroup) parent.getChildAt(i)).setClipChildren(false);
        Log.i("FontSize", "Set font size to " + 10 / childCount);
        ((TextView) parent.getChildAt(i).findViewById(R.id.name_text)).setTextScaleX(10 / childCount);// .setTextSize(10/childCount);
    }
}

此方法在 ViewTreeObserver 中执行,因此在呈现 UI 之后。

如何在不切断文本的情况下调整文本大小?

最佳答案

SetTextScaleX 在 X 方向(水平)拉伸(stretch)文本。看起来更像是您想缩小文本,使其从上到下变小,对吗?在那种情况下,您不需要 setTextScaleX,您需要 setTextSize。

关于android - 以编程方式调整文本大小,文本超出 Viewbounds,修复了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14883101/

相关文章:

iphone - 调整 iPad CSS 布局以适应 iPhone 屏幕

android - 导出的服务不需要权限 : what does it mean?

android - theme.appcompat.light 的默认文本颜色是什么?

android - 下载 PDF 时 InputStream 返回空文件

c# - 实现相互使用的类型化接口(interface)的问题

command-line - 如何禁用 SMLNJ 警告?

android - 如何将相机预览流从 android 连接到 Qt5?

javascript - 检测 <object> 元素的宽度/高度何时更改

android - 在对话框中选择微调器时 Android Espresso 中的 RunTimeException

latex - 在 LaTeX 投影仪中调整矩阵大小