【发布时间】:2019-07-20 13:30:18
【问题描述】:
所以我想要一个标题总是占屏幕的三分之一,然后在屏幕的其余三分之二的地方加上名字。看起来很简单,但结果是,如果有很多名字,标题会变成不到三分之一。我只写了两行代码 //1 //2 以便轻松找到它们,但给出整个代码,因为它可能会影响结果。
这是一张照片。 The top text does not show the whole message and Is not 1 third of the screen as intended 提前致谢!
private void showScores() {
float baseTextSize = 100/playerNum;
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT,
10000.0f //1
);
TextView t = new TextView(this);
String result_msg = getString(R.string.result_msg);
t.setLayoutParams(param);
t.setText(result_msg + "\n");
t.setTextColor(getColor(R.color.white));
if (playerNum>3) {
t.setTextSize(30f);
} else {
t.setTextSize(40f);
}
scoreShower.addView(t);
param.weight = 20000.0f/playerNum; //2
for (int i=0;i<playerNum;i++) {
TextView txt = new TextView(this);
txt.setLayoutParams(param);
if (i == 0) {
txt.setTextSize(baseTextSize + 8f);
txt.setTextColor(getColor(R.color.gold));
} else {
txt.setTextSize(baseTextSize);
txt.setTextColor(getColor(R.color.white));
}
String txtString = (i+1) + ". " + arrayList.get(i).getKey() + " : " + arrayList.get(i).getValue();
txt.setText(txtString);
if (playerNum>6) {
txt.setTextSize(10f);
}
scoreShower.addView(txt);
}
【问题讨论】:
-
添加 param.height=0 没有帮助。添加了结果照片,点击蓝色文字
标签: android android-linearlayout android-layout-weight