如何将文字大小设置为双倍大小

How To Set Text Size To A Double

所以我试图将 TextView 的文本大小设置为 double 变量。

Android Studio 不喜欢它,因为它需要一个 float 变量,但这些字母的大小必须准确,因为该项目是一家医疗公司。

有什么想法可以让它发挥作用吗?

谢谢!

编辑 我现在已经实施了下面的建议,但是文本没有显示在屏幕上。这是下面的代码:

public class Test extends AppCompatActivity {
String PREFS_NAME = "VALUES";
int DEF_VAL = 0;
double final_calc1;
double final_calc2;
double DIST_SCALE = 0;
double size = DIST_SCALE * 2;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SharedPreferences DIST = getSharedPreferences(PREFS_NAME, 0);
    int f1 = DIST.getInt("value1", DEF_VAL);
    int f2 = DIST.getInt(value2", DEF_VAL);
    final_calc1 = f2 / 12;
    final_calc2 = final_calc1 + f1;
    DIST_SCALE = final_calc2 * .1875;
    //were everything is scaled based on the values ^^^
    //I am also positive that shared references is getting the required
    //values, I tested that part earlier
    setContentView(R.layout.standard_400);
    TextView letter = (TextView)findViewById(R.id.standard_400_line1);
    letter.setTextSize((float) size);


}
}

当我加载它时 运行 它在模拟器中什么也没有出现,有什么办法可以解决这个问题吗? 再次感谢!

虽然您的 double 变量将用于设置 文本大小 ,因此它足够小以适合 float.

我建议您将 double 转换为 float,例如:

double d = 24.64;
yourTextView.setTextSize( (float) d);

注意事项:

浮动

4 bytes, IEEE 754.

Covers a range from 1.40129846432481707e-45 to 3.40282346638528860e+38 (positive or negative).

8 bytes IEEE 754.

Covers a range from 4.94065645841246544e-324d to 1.79769313486231570e+308d (positive or negative).