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 楼答案
而
double
变量将用于设置文本大小,因此它将足够小,适合float
我建议你把你的
double
投到float
,例如:注意:
漂浮
加倍