gpt4 book ai didi

java - 这个 Android 代码 fragment 在做什么?

转载 作者:太空宇宙 更新时间:2023-11-04 12:25:21 25 4
gpt4 key购买 nike

编辑**找出了我自己的答案,除了我的主要问题如下:

            TableLayout tableLayout = new TableLayout(this);

TableRow row = new TableRow(getApplicationContext());
row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
// inner for loop
for (int j = 1; j <= courseHoleCount; j++) {
**TextView tv = new TextView(getApplicationContext());
tv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));**
tv.setBackgroundResource(R.drawable.cell_shape);
tv.setTextSize(30);
tv.setPadding(5, 5, 5, 5);
tv.setText(String.valueOf(players[i-1].getScore()[j-1]));// (-1) because j = 1 and not 0.
row.addView(tv);
}
tableLayout.addView(row);


linearLayout.addView(tableLayout);

在上面的代码 fragment 中,它有什么作用以及什么/为什么将 TableRow.Layout 参数添加到 TextView 布局参数中?

tv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));

最佳答案

使用

TableRow.LayoutParams 是因为 tvrow 的子级,而 rowTableRow。如果你看Android API reference ,它说

Set the layout parameters associated with this view. These supply parameters to the parent of this view specifying how it should be arranged.

LayoutParams构造函数的两个参数用于设置tv的宽度和高度。由于宽度和高度都设置为 WRAP_CONTENT,因此 tv 的大小 will be big enough to enclose its content (plus padding) .

关于java - 这个 Android 代码 fragment 在做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38446857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com