【发布时间】:2019-02-04 12:04:11
【问题描述】:
我正在尝试以编程方式创建 textView 并在其上设置 setHeight、setWidth 和自动文本大小。 textview 运行良好,但自动文本大小不起作用! 请帮帮我。
AbsoluteLayout absoluteLayout = findViewById(R.id.absoluteLayout);
TextView textView = new TextView(MainActivity.this);
textView.setText("Hi Ali");
textView.setWidth(300);
textView.setHeight(100);
textView.setX(100);
textView.setY(40);
TextViewCompat.setAutoSizeTextTypeWithDefaults(textView, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);
//border
GradientDrawable gd = new GradientDrawable();
gd.setStroke(2, 0xFF000000);
gd.setCornerRadius(5);
textView.setBackground(gd);
absoluteLayout.addView(textView);
及其我的 xml 代码
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/absoluteLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
【问题讨论】: