有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何将文本大小设置为双精度

因此,我试图将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);


}
}

当我加载它并在模拟器中运行它时,什么都没有出现,你知道我如何解决这个问题吗? 再次感谢


共 (1) 个答案

  1. # 1 楼答案

    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).