gpt4 book ai didi

java - 如何在android中创建动态水平表格行?

转载 作者:行者123 更新时间:2023-11-29 06:04:26 25 4
gpt4 key购买 nike

我当前的代码是:

for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
String b = json_data.getString("examnames");
JSONObject getexamnamesobject = new JSONObject(b);
getexamnames=getexamnamesobject.getString("types");
TableRow tr = new TableRow(this);
TextView tv1 = new TextView(this);
createView(tr,tv1,getexamnames);
t1.addView(tr);
}
public void createView(TableRow tr, TextView t, String viewdata) {
t.setText(viewdata);
//adjust the porperties of the textView
t.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
//t.setTextColor(Color.DKGRAY);
//t.setBackgroundColor(Color.CYAN);
t.setPadding(20, 0, 0, 0);
tr.setPadding(0, 1, 0, 1);
//tr.setBackgroundColor(Color.BLACK);
tr.addView(t); // add TextView to row.
}

上面代码的输出是,我像这样垂直获取 TextView :

English
Maths
Science

为了得到这样的水平输出,上面的代码必须改变什么:

English Maths Science

请帮帮我。这对我来说很重要提前致谢

最佳答案

将 setStretchAllColumns() 和 setShrinkAllColumns() 设置为表格布局。并将其设置为表格布局的“水平”方向。

关于java - 如何在android中创建动态水平表格行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9030196/

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