Android 我可以在TextView中更改字体高度吗
我正在使用此AutoFitTextView: 工作正常,显示所有文本,调整字体大小 问题是我想增加高度,因为有可用的空间,因为你看到的边界有空间 Java代码:Android 我可以在TextView中更改字体高度吗,android,fonts,textview,Android,Fonts,Textview,我正在使用此AutoFitTextView: 工作正常,显示所有文本,调整字体大小 问题是我想增加高度,因为有可用的空间,因为你看到的边界有空间 Java代码: PercentRelativeLayout layout = (PercentRelativeLayout) findViewById(R.id.temp_layout); AutoTxtV txtV = new AutoTxtV(this); txtV.setMaxLines(1); txtV.se
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>
有没有办法增加高度,或者改变字体
更新(更多解释):
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);
问题是我希望字体“高度”增加,而不是“大小”,因为如果我增加大小,文本将不会全部显示
在AutoFitTextView中,调整文本“size”(宽度和高度)因为容器的“宽度”不够,我只想减小“宽度”,因为宽度只是问题所在。这两种方法解决了我的问题:
<?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>
txtV.setScaleY()-更改高度
txt.setTextScaleX()这是textview后面的视图还是任何布局?@quicklearner我更新了要点,父级是布局类型:PercentRelativeLayout你应该让它包装内容,而不是尝试textview高度