[英]Dynamic Span Adjustment for TextView In TableLayout
Is there a way that I can set the span of a textview object in the java code, instead of having to do it in xml? Is there a way that I can set the span of a textview object in the java code, instead of having to do it in xml? I tried someone else's solution of using LayoutParams .
我尝试了其他人使用LayoutParams的解决方案。 I don't know if i didn't implement it correctly or if its just the wrong solution or maybe im just not realizing what my mistake in the code is, but it's causing the application to crash.
我不知道我是否没有正确实现它,或者它只是错误的解决方案,或者我只是没有意识到我在代码中的错误是什么,但这导致应用程序崩溃。 Any help would be appreciated, im posting my code below.
任何帮助将不胜感激,我在下面发布我的代码。
package com.szymon.atrium;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;
public class TapeChart extends Activity
{
private ArrayList<Room> rooms;
private ArrayList<Arrival> arrivals;
private GregorianCalendar startDate = new GregorianCalendar(2011,1,1);
private GregorianCalendar endDate = new GregorianCalendar(2011,1,10);
private ArrivalGrid grid = new ArrivalGrid(arrivals, rooms, startDate.getTime(), endDate.getTime());
private ArrayList<ArrayList<Cell>> displayArrival = grid.displayArrivalGrid();
private ArrayList<ArrayList<Cell>> displayRooms = grid.displayRoomGrid();
@Override
public void onCreate(Bundle bundle)
{
super.onCreate(bundle);
setContentView(R.layout.tape);
TableLayout tbl = (TableLayout)findViewById(R.id.tapeChart);
for(ArrayList<Cell> a : displayRooms)
{
TableRow newRow = new TableRow(this);
for(Cell c : a)
{
LayoutParams param = new LayoutParams();
param.span=c.getColSpan();
MyTextView cell = new MyTextView(this);
cell.setText(c.getContent());
cell.setLayoutParams(param);
newRow.addView(cell);
}
tbl.addView(newRow);
}
}
public TableLayout getArrivalsTableLayout()
{
return null;
}
public void getRoomTableLayout()
{
}
} }
With the aid of the code at this link , I have accomplish this issue like that借助此链接上的代码,我已经完成了这个问题
`TableRow.LayoutParams rowSpanLayout = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
rowSpanLayout.span = 3;
TextView textView = new TextView(this);
textView.setText("Text Title");
tableRow.addView(textView, rowSpanLayout);`
while creating rows dynamically at java code side.同时在 java 代码端动态创建行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.