【问题标题】:Can I change Height of font in TextView我可以在 TextView 中更改字体的高度吗
【发布时间】:2017-03-21 21:50:07
【问题描述】:

我正在使用这个 AutoFitTextView :http://www.andreamaglie.com/android-auto-fit-textview/

它工作正常,显示所有文本并调整字体大小,

问题是我想增加高度,因为有可用空间,因为你看到边界有空间。

Java 代码:

   PercentRelativeLayout layout = (PercentRelativeLayout) findViewById(R.id.temp_layout);


    AutoTxtV txtV = new AutoTxtV(this);
    txtV.setMaxLines(1);
    txtV.setMinTextSize(1);
    txtV.setTextSize(TypedValue.COMPLEX_UNIT_SP,16);
    txtV.setGravity(Gravity.CENTER_VERTICAL);
    txtV.setTextColor(getResources().getColor(R.color.card_name_white));


    txtV.setText("HELLO WORLD HELLO WORLD ABCDEFGHIJKLM");


    layout.addView(txtV);

XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout           xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/parent_layout"
android:layout_width="279dp"
android:layout_height="405dp"
android:background="@drawable/background">



<android.support.percent.PercentRelativeLayout
    android:id="@+id/temp_layout"
    android:orientation="horizontal"
    app:layout_heightPercent="7.5%"
    app:layout_marginLeftPercent="7.3%"
    app:layout_marginTopPercent="4%"
    app:layout_widthPercent="74.5%">
</android.support.percent.PercentRelativeLayout>
</android.support.percent.PercentRelativeLayout>

有没有办法增加高度,也许改变字体类型?

更新(更多解释):

问题是我希望字体“高度”增加而不是“大小”,因为如果我增加大小,文本将不会全部显示。

AutoFitTextView,调整文本“大小”(宽度和高度) 因为容器的“宽度”不够,我只想减小“宽度”,因为宽度只有问题。

【问题讨论】:

  • 是视图还是 textview 后面的任何布局?
  • @quicklearner 我更新了要点,父级布局类型为 :PercentRelativeLayout
  • 你应该让它包裹内容而不是尝试 textviews 高度

标签: android fonts textview


【解决方案1】:

这两个解决了我的问题:

txtV.setScaleY() - 改变高度

txt.setTextScaleX()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 2018-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多