首页 文章

我可以在TextView中更改字体的高度

提问于
浏览
0

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

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

enter image description here

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

Java code :

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>

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

UPDATE (more explain):

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

AutoFitTextView,调整文本大小"size" (width and height) 因为容器的"width"不够,我只想减少"width"以来宽度只有问题 .

1 回答

  • 0

    These two solve my problem :

    txtV.setScaleY() - 更改高度

    txt.setTextScaleX()

相关问题