本文介绍了如何给细胞的边界tablelayout在安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题,如何给单元格边框Android中的tablelayout编程。
这是我的code:
TableLayout表=(TableLayout)findViewById(R.id.linear_Layout_List);
连续的TableRow = NULL;
ROW1的TableRow = NULL;
按钮标签= NULL;
INT大小= items.size();
的for(int i = 0; I<大小-2,I + = 3)
{
行=新的TableRow(SearchGridActivity.this);
row.setId(100 + I);
为(J = 0; J&所述; 3; J ++)
{
/*TableLayout.LayoutParams tableRowParams =
新TableLayout.LayoutParams
(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
INT LEFTMARGIN = 10;
INT TOPMARGIN = 2;
INT rightMargin = 10;
INT bottomMargin = 2;
tableRowParams.setMargins(LEFTMARGIN,TOPMARGIN,rightMargin,bottomMargin);
row.setLayoutParams(tableRowParams); * /
如果(count_img!= NUM_RESULTS)
{
//row.setPadding(10,2,10,0);
视图V = View.inflate(这一点,R.layout.tablecell,NULL);
的LinearLayout奠定=(的LinearLayout)v.findViewById(R.id.linear_table);
/ * MarginLayoutParams的LayoutParams =新MarginLayoutParams(
LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(30,20,30,0); * /
最后ImageView的IMG =新ImageView的(这一点);
img.setImageBitmap(imageBitmap [count_img]);
img.setClickable(真正的);
img.setId(count_img);
img.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(查看为arg0){
BaseInventoryItem项= items.get(img.getId());
如果(项目的instanceof优惠){
SearchResultActivity.list_flag = FALSE;
grid_flag = TRUE;
意向意图=新的意图(SearchGridActivity.this,ProductComparisonActivity.class);
intent.putExtra(项目,项目);
startActivity(意向);
}否则,如果(项目的instanceof产品){
SearchResultActivity.list_flag = FALSE;
grid_flag = TRUE;
意向意图=新的意图(SearchGridActivity.this,ProductComparisonActivity.class);
intent.putExtra(项目,项目);
startActivity(意向);
}
}
});
BaseInventoryItem项目= items.get(count_img);
TextView的txt_price =新的TextView(本);
如果(项目的instanceof优惠){
发售的发售=(优惠)项目;
txt_price.setText(offer.getPrice()用getPrice());
txt_price.setTextColor(Color.BLACK);
txt_price.setTextSize(15);
}否则,如果(项目的instanceof产品){
产品产品=(产品)项目;
txt_price.setText(从+ product.getPriceSet()getMinPrice()用getPrice());
txt_price.setTextColor(Color.BLACK);
txt_price.setTextSize(15);
}
lay.addView(IMG);
lay.addView(txt_price);
row.addView(五);
count_img ++;
}
}
//row.addView(label);
table.addView(行);
}
/ * ROW1 =新的TableRow(SearchGridActivity.this);
row1.setId(10001); * /
的TableRow ROW2 =(的TableRow)View.inflate(这一点,R.layout.tablerow,NULL);
按钮btn_load =(按钮)row2.findViewById(R.id.btn_table_LoadMore);
btn_load.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(查看为arg0){
NUM_RESULTS = NUM_RESULTS + 12;
意向意图=新的意图(SearchGridActivity.this,SearchGridActivity.class);
intent.putExtra(关键字,关键字);
startActivity(意向);
}
});
/ * row1.setLayoutParams(新的LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT)); * /
TableRow.LayoutParams rowSpanLayout =新TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT,TableRow.LayoutParams.FILL_PARENT);
rowSpanLayout.span = 3;
//row.setBackgroundColor(0xff222222);
标签=新按钮(SearchGridActivity.this);
label.setText(加载更多);
//label.setBackgroundColor(Color.BLUE);
//row1.addView(label);
//row.addView(label);
table.addView(ROW2,rowSpanLayout);
解决方案
有这样做的没有直接的方法。你必须摆弄背景 利润率和填充
最后我用这样的事情
< TableLayout机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:stretchColumns =*的android:背景=#FF0000>
<的TableRow机器人:后台=#00FF00机器人:layout_margin =2DIP>
<按钮机器人:ID =@ + ID /按钮机器人:文本=+机器人:后台=#0000FF机器人:layout_margin =2DIP/>
< TextView的Android版本:文本=@字符串/标签机器人:后台=#0000FF机器人:layout_margin =2DIP/>
< TextView的机器人:ID =@ + ID /量机器人:后台=#0000FF机器人:layout_margin =2DIP/>
< /的TableRow>
这是在这里拍摄。 LINK
I have a question that how to give cell borders in tablelayout of Android programmatically.
Here is my Code:
TableLayout table = (TableLayout)findViewById(R.id.linear_Layout_List);
TableRow row=null;
TableRow row1=null;
Button label = null;
int size=items.size();
for (int i = 0; i < size-2; i+=3)
{
row = new TableRow(SearchGridActivity.this);
row.setId(100+i);
for(j=0;j<3;j++)
{
/*TableLayout.LayoutParams tableRowParams=
new TableLayout.LayoutParams
(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
int leftMargin=10;
int topMargin=2;
int rightMargin=10;
int bottomMargin=2;
tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
row.setLayoutParams(tableRowParams);*/
if(count_img!=NUM_RESULTS)
{
//row.setPadding(10, 2, 10, 0);
View v = View.inflate(this, R.layout.tablecell, null);
LinearLayout lay = (LinearLayout)v.findViewById(R.id.linear_table);
/*MarginLayoutParams layoutParams = new MarginLayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(30, 20, 30, 0);*/
final ImageView img = new ImageView(this);
img.setImageBitmap(imageBitmap[count_img]);
img.setClickable(true);
img.setId(count_img);
img.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
BaseInventoryItem item = items.get(img.getId());
if (item instanceof Offer) {
SearchResultActivity.list_flag = false;
grid_flag = true;
Intent intent = new Intent(SearchGridActivity.this, ProductComparisonActivity.class);
intent.putExtra("item", item);
startActivity(intent);
} else if (item instanceof Product) {
SearchResultActivity.list_flag = false;
grid_flag = true;
Intent intent = new Intent(SearchGridActivity.this, ProductComparisonActivity.class);
intent.putExtra("item", item);
startActivity(intent);
}
}
});
BaseInventoryItem item = items.get(count_img);
TextView txt_price = new TextView(this);
if (item instanceof Offer) {
Offer offer = (Offer) item;
txt_price.setText(offer.getPrice().getPrice());
txt_price.setTextColor(Color.BLACK);
txt_price.setTextSize(15);
} else if (item instanceof Product) {
Product product = (Product) item;
txt_price.setText("from " + product.getPriceSet().getMinPrice().getPrice());
txt_price.setTextColor(Color.BLACK);
txt_price.setTextSize(15);
}
lay.addView(img);
lay.addView(txt_price);
row.addView(v);
count_img++;
}
}
//row.addView(label);
table.addView(row);
}
/* row1 = new TableRow(SearchGridActivity.this);
row1.setId(10001);*/
TableRow row2 = (TableRow) View.inflate(this, R.layout.tablerow, null);
Button btn_load = (Button)row2.findViewById(R.id.btn_table_LoadMore);
btn_load.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
NUM_RESULTS = NUM_RESULTS+12;
Intent intent = new Intent(SearchGridActivity.this,SearchGridActivity.class);
intent.putExtra("keyword", keyword);
startActivity(intent);
}
});
/* row1.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));*/
TableRow.LayoutParams rowSpanLayout = new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.FILL_PARENT);
rowSpanLayout.span = 3;
//row.setBackgroundColor(0xff222222);
label = new Button(SearchGridActivity.this);
label.setText("Load More");
//label.setBackgroundColor(Color.BLUE);
//row1.addView(label);
//row.addView(label);
table.addView(row2,rowSpanLayout);
解决方案
there is no direct way of doing this. you have to mess around with background, margins and padding.
i ended up using something like this
<TableLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*" android:background="#ff0000">
<TableRow android:background="#00ff00" android:layout_margin="2dip">
<Button android:id="@+id/button" android:text="+" android:background="#0000ff" android:layout_margin="2dip"/>
<TextView android:text="@string/label" android:background="#0000ff" android:layout_margin="2dip"/>
<TextView android:id="@+id/amount" android:background="#0000ff" android:layout_margin="2dip"/>
</TableRow>
taken from here. LINK
这篇关于如何给细胞的边界tablelayout在安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!