android tablerow 动态添加,android-通过sql循环将多个TextView动态添加到TableRow

我在这里搜索过,但似乎无法解决此问题.我有一个ScrollView,在ScrollView内是LinearLayout,我想读取我的SQL数据库并显示类似的结果;

Linear Layout

ScrollView

Linear Layout

TableRow

TextView

TextView

TableRow

TextView

TextView

/Linear Layout

/ScrollView

/LinearLayout

我的代码如下:

TableRow tRow;

ContextThemeWrapper ttRow = new ContextThemeWrapper(this, R.style.coreTable);

LinearLayout LL = (LinearLayout) findViewById(R.id.linearCores);

LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

if (cores.moveToFirst()) {

while (cores.isAfterLast() == false) {

Log.e("CORE LIST", cores.getString(1));

tRow = new TableRow(ttRow);

tRow.setLayoutParams(lp);

tRow.setOrientation(TableRow.VERTICAL);

tRow.setId(cores.getInt(0));

tRow.setBackgroundResource(R.drawable.shape_border);

ContextThemeWrapper newTxtA = new ContextThemeWrapper(this, R.style.coreHeaderView);

TextView tTextA = new TextView(newTxtA);

tTextA.setLayoutParams(lp);

tTextA.setText(cores.getString(1) + " (Lvl " + cores.getString(2) + ")");

tRow.addView(tTextA);

TextView tTextB = new TextView(coreChooser.this);

tTextB.setLayoutParams(lp);

tTextB.setText(cores.getString(5));

tRow.addView(tTextB);

LL.addView(tRow);

cores.moveToNext();

}

}

在我的模拟器上,它显示了第一个tRow.addView,但没有显示其他内容,但是背景显示似乎已经超过了屏幕.

我真的不确定在这里我做错了什么.

解决方法:

TableRow的文档指出以下内容:

A TableRow should always be used as a child of a TableLayout. If a TableRow‘s parent is not a TableLayout, the TableRow will behave as an horizontal LinearLayout.

如果您只是想让每对TextView共享公共背景R.drawable.shape_border,则可以使用嵌套的LinearLayout代替TableRow(无论如何,TableRow是从LinearLayout扩展的).

或者,如果您确实要使用TableRow的某些特定功能,则使R.id.linearCores为TableLayout而不是LinearLayout.

标签:tablerow,android-linearlayout,android,textview

来源: https://codeday.me/bug/20191119/2034579.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值