public TableRow createRow(String rowName, String rowValue, int colour) { TableRow tableRow = new TableRow(context); tableRow.setLayoutParams( new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); TextView textView = new TextView(context); textView.setText(rowName); textView.setTextColor(colour); textView.setTextSize(20.0f); TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(0); layoutParams.width = 175; textView.setLayoutParams(layoutParams); TextView textViewValue = new TextView(context); textViewValue.setText(rowValue); textViewValue.setTextColor(colour); textViewValue.setTextSize(20.0f); textViewValue.setGravity(Gravity.RIGHT); textViewValue.setLayoutParams(new TableRow.LayoutParams(1)); tableRow.addView(textView); tableRow.addView(textViewValue); return tableRow; }
/** Creates a blank space to fill the row. */ private ImageView createBlankSpace() { ImageView view = new ImageView(getContext()); TableRow.LayoutParams params = new TableRow.LayoutParams(mSwatchLength, mSwatchLength); params.setMargins(mMarginSize, mMarginSize, mMarginSize, mMarginSize); view.setLayoutParams(params); return view; }
public static void setMargins(View view, int margin) { TableRow.LayoutParams params = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, Gravity.RIGHT); params.setMargins(margin, margin, margin, margin); view.setLayoutParams(params); }
private void addTableRow(TableLayout table, String parameter, String value) { TableRow row = new TableRow(table.getContext()); TableRow.LayoutParams trParams = new TableRow.LayoutParams(); trParams.setMargins(2, 2, 2, 1); row.setLayoutParams(trParams); row.setBackgroundColor(Color.rgb(0x00, 0x00, 0x00)); TextView text1 = new TextView(row.getContext()); text1.setTextSize(18); text1.setText(parameter); text1.setBackgroundColor(Color.rgb(0x18, 0x18, 0x18)); text1.setLayoutParams(trParams); text1.setPadding(5, 0, 0, 0); row.addView(text1); TextView text2 = new TextView(row.getContext()); text2.setTextSize(18); text2.setText(value); text2.setBackgroundColor(Color.rgb(0x18, 0x18, 0x18)); text2.setLayoutParams(trParams); text2.setPadding(5, 0, 0, 0); row.addView(text2); table.addView(row); }
public void addFlagElement() { LinearLayout item = new LinearLayout(this); item.setBackgroundColor(Color.BLACK); item.setLayoutParams(Tools.setMargins()); item.setBackgroundResource(R.drawable.shape); item.setWeightSum(10f); ImageView iv = new ImageView(this); iv.setBackgroundResource(R.drawable.flag); TableRow.LayoutParams ivparams = new TableRow.LayoutParams(75, 75); ivparams.setMargins(25, 25, 55, 25); iv.setLayoutParams(ivparams); TextView tv = new TextView(this); TableRow.LayoutParams tvparams = new TableRow.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); tvparams.gravity = Gravity.CENTER; tv.setLayoutParams(tvparams); tv.setText("Flag is set here!!!"); tv.setTextColor(Color.WHITE); item.addView(iv); item.addView(tv); body.addView(item); addTimeStamp(); }
/** Creates a color swatch. */ private ColorPickerSwatch createColorSwatch(int color, int selectedColor) { ColorPickerSwatch view = new ColorPickerSwatch( getContext(), color, color == selectedColor, mOnColorSelectedListener); TableRow.LayoutParams params = new TableRow.LayoutParams(mSwatchLength, mSwatchLength); params.setMargins(mMarginSize, mMarginSize, mMarginSize, mMarginSize); view.setLayoutParams(params); return view; }
private void BuildTable(int rows, int cols) { try { // outer for loop for (int i = 1; i <= rows; i++) { TableRow row = new TableRow(getActivity()); row.setBackgroundResource(R.drawable.layout_border5); /* row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); */ TableRow.LayoutParams params = new TableRow.LayoutParams( TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT); params.setMargins(2, 2, 0, 0); row.setLayoutParams(params); // inner for loop for (int j = 1; j <= cols; j++) { TextView tv = new TextView(getActivity()); tv.setLayoutParams( new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); // tv.setBackgroundResource(R.drawable.cell_shape); if (j == 1) { tv.setPadding(40, 5, 10, 10); } else { tv.setPadding(80, 10, 10, 14); } try { tv.setText(" " + monthlyOrders.get(i - 1)); } catch (Exception e) { e.printStackTrace(); } if (j == 2) { tv.setText(" " + orders_inprogress.get(i - 1)); } if (j == 3) { tv.setText(" " + orders_completed.get(i - 1)); } row.addView(tv); } table_layout.addView(row); } } catch (Exception e) { e.printStackTrace(); } }
public void addTimeStamp() { TextView tv = new TextView(this); TableRow.LayoutParams tvparams_time = new TableRow.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); tvparams_time.gravity = Gravity.RIGHT; tv.setText(Tools.getTimeStamp()); tv.setTextColor(Color.GRAY); tv.setTextSize(10f); tv.setLayoutParams(tvparams_time); tv.setPadding(0, 0, 5, 0); body.addView(tv); }
private void buildTable() { db = helper.getReadableDatabase(); Cursor c = helper.readEntry(db); int rows = c.getCount(); int columns = c.getColumnCount(); c.moveToFirst(); for (int i = 0; i < rows; i++) { TableRow row = new TableRow(this); row.setLayoutParams( new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); // for (int j = 0; j < columns; j++) { // content = content + " at " + c.getString(j); // } String content = c.getString(0) + " at " + c.getString(1); TextView tv = new TextView(this); TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); int topMargin = 3; int bottomMargin = 3; tableRowParams.setMargins(0, topMargin, 0, bottomMargin); tv.setLayoutParams(tableRowParams); tv.setBackgroundResource(R.drawable.cell_shape); tv.setGravity(Gravity.CENTER); tv.setTextSize(18); tv.setTextColor(Color.WHITE); tv.setText(content); row.addView(tv); c.moveToNext(); table_layout.addView(row); } helper.close(); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ScrollView sv = new ScrollView(getActivity()); TableLayout tl = new TableLayout(getActivity()); sv.addView(tl); if (displayReportController == null) { return sv; } AdsenseReportsGenerateResponse response = displayReportController.getReportResponse(); TableLayout.LayoutParams tableRowParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); tableRowParams.setMargins(10, 10, 10, 10); TableRow.LayoutParams tvParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); tvParams.setMargins(10, 10, 10, 10); List<Headers> headers = response.getHeaders(); TableRow tr = new TableRow(getActivity()); tl.addView(tr); for (Headers header : headers) { TextView tv = new TextView(getActivity()); tv.setText(header.getName()); tr.setLayoutParams(tableRowParams); tr.addView(tv); } if (response.getRows() != null && !response.getRows().isEmpty()) { for (List<String> row : response.getRows()) { TableRow trow = new TableRow(getActivity()); tl.addView(trow); for (String cell : row) { TextView tv = new TextView(getActivity()); tv.setText(cell); trow.addView(tv); tv.setLayoutParams(tvParams); tv.setPadding(15, 5, 15, 5); tv.setBackgroundColor(Color.WHITE); } } } return sv; }
public TableRow getTableTitleView() { TableRow rowTitle = new TableRow(getActivity()); rowTitle.setGravity(Gravity.CENTER_HORIZONTAL); TextView title = new TextView(getActivity()); title.setText(form.getTableName()); title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); // title.setGravity(Gravity.CENTER); title.setTypeface(Typeface.SERIF, Typeface.BOLD); TableRow.LayoutParams params = new TableRow.LayoutParams(); params.span = columnNames.length; rowTitle.addView(title, params); return rowTitle; }
private TableRow buildAmenityTableRow(Context ctx, Amenity amenity) { TextView textView = new TextView(ctx); String amName = amenity.name(); int id = getResources().getIdentifier(ctx.getPackageName() + ":string/" + amName, null, null); String value = ctx.getString(id); textView.setText(value); textView.setGravity(Gravity.RIGHT); CheckBox checkBox = new CheckBox(ctx); checkBox.setChecked(false); checkBox.setOnCheckedChangeListener(new AmenityOnCheckChangeListener(this.amenities, amenity)); TableRow tableRow = new TableRow(ctx); TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(); layoutParams.setMargins(0, 0, 10, 0); tableRow.addView(textView, layoutParams); tableRow.addView(checkBox); return tableRow; }
@SuppressLint("NewApi") public void addPhotoElement(Uri imgUri) { LinearLayout item = new LinearLayout(this); item.setBackgroundColor(Color.BLACK); item.setBackgroundResource(R.drawable.shape); TableRow.LayoutParams item_params = new TableRow.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); // item_params.gravity =Gravity.RIGHT; item_params.setMargins(5, 8, 5, 8); item.setLayoutParams(item_params); item.setPadding(-20, 40, -20, 40); // item.setPadding(-30, 20, -30, 20); ImageView iv = new ImageView(this); TableRow.LayoutParams iv_params = new TableRow.LayoutParams(500, 500); iv.setLayoutParams(iv_params); iv.setImageURI(imgUri); item.addView(iv); body.addView(item); addTimeStamp(); }
private void updateTable() { tbLayout.removeAllViews(); for (SensorMeasure measure : this.mainListSensorMeasures) { if ((calendarFilter != null) && (measure.getTimestamp().getTimeInMillis() < calendarFilter.getTimeInMillis())) continue; // Si la medida es anterior al filtro, nos la saltamos TableRow row = new TableRow(this); TextView tvDate = new TextView(this); TableRow.LayoutParams params = new TableRow.LayoutParams(); params.column = 1; params.gravity = Gravity.LEFT; tvDate.setLayoutParams(params); tvDate.setText(DateFormat.getDateTimeInstance().format(measure.getTimestamp().getTime())); TextView tvValue = new TextView(this); tvValue.setGravity(Gravity.RIGHT + Gravity.FILL_HORIZONTAL); tvValue.setText(measure.getValue()); row.addView(tvDate); row.addView(tvValue); tbLayout.addView(row); } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final OfflineTabActivity activity = (OfflineTabActivity) getActivity(); menu = activity.getMenu(); View rootView = inflater.inflate(R.layout.menu_layout, container, false); ScrollView scroll = new ScrollView(getActivity().getApplicationContext()); TableLayout menulist = new TableLayout(getActivity().getApplicationContext()); TableRow.LayoutParams param = new TableRow.LayoutParams(); param.setMargins(0, 0, 15, 0); final String sid = "4"; int id = 0; for (Beverage beverage : menu) { if (beverage.getType().equals("soft")) { id++; TableRow row = new TableRow(getActivity().getApplicationContext()); TextView tekst = new TextView(getActivity().getApplicationContext()); tekst.setText(beverage.getName()); tekst.setLayoutParams(param); tekst.setId(Integer.parseInt(sid + id)); row.addView(tekst); TextView amount = new TextView(getActivity().getApplicationContext()); amount.setText("€ " + beverage.getPrice()); amount.setLayoutParams(param); row.addView(amount); menulist.addView(row); } } scroll.setPadding(20, 5, 0, 5); scroll.addView(menulist); return scroll; }
private void addTableRow( TableLayout layout, int rank, String name, int score, boolean textStyleBold) { TableRow row = new TableRow(HighscoreActivity.this); TextView textViewNumber = new TextView(HighscoreActivity.this); textViewNumber.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 30); textViewNumber.setText(rank + "."); TableRow.LayoutParams layoutParamsLeft = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); layoutParamsLeft.gravity = Gravity.START; textViewNumber.setLayoutParams(layoutParamsLeft); row.addView(textViewNumber); TextView textViewPlayer = new TextView(HighscoreActivity.this); textViewPlayer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 30); if (name.length() > 14) { name = name.substring(0, 11) + "..."; } textViewPlayer.setText(name); TableRow.LayoutParams layoutParamsCenter = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); layoutParamsCenter.gravity = Gravity.CENTER; textViewPlayer.setLayoutParams(layoutParamsCenter); row.addView(textViewPlayer); TextView textViewScore = new TextView(HighscoreActivity.this); textViewScore.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 30); textViewScore.setText(String.valueOf(score)); TableRow.LayoutParams layoutParamsRight = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); layoutParamsRight.gravity = Gravity.END; textViewScore.setLayoutParams(layoutParamsRight); row.addView(textViewScore); if (textStyleBold) { textViewNumber.setTypeface(null, Typeface.BOLD_ITALIC); textViewPlayer.setTypeface(null, Typeface.BOLD_ITALIC); textViewScore.setTypeface(null, Typeface.BOLD_ITALIC); } layout.addView(row); }
public TableRow createRow( View image, String appName, String date, Double value, String reason, Context activity) { TableRow row = new TableRow(activity); row.setGravity(Gravity.CENTER); image.setPadding((int) (ratio * 10), 0, (int) (ratio * 15), 0); ((LinearLayout) image).setGravity(Gravity.LEFT); LinearLayout img = new LinearLayout(row.getContext()); img.setLayoutParams( new LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); img.setOrientation(LinearLayout.HORIZONTAL); img.setGravity(Gravity.CENTER); img.addView(image); row.addView( img, new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, (int) (ratio * 70))); LinearLayout main = new LinearLayout(row.getContext()); main.setLayoutParams( new LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); main.setOrientation(LinearLayout.VERTICAL); TextView appname = new TextView(activity); appname.setText(appName); appname.setPadding(0, 0, 0, 0); appname.setTextColor(Color.parseColor("#545859")); appname.setMaxLines(1); appname.setTextSize(16); appname.setLayoutParams( new LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); TextView movdate = new TextView(activity); // PARSE DATE AND SET TEXTVIEW try { SimpleDateFormat curFormater = new SimpleDateFormat("d-MMM-y HH:mm:ss", Locale.ENGLISH); curFormater.setTimeZone(TimeZone.getTimeZone("GMT")); Date endDate = curFormater.parse(date); curFormater.setTimeZone(TimeZone.getDefault()); movdate.setText( DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault()) .format(endDate)); movdate.setPadding(0, 0, 0, 0); movdate.setTextColor(Color.parseColor("#787A77")); movdate.setTextSize(12); } catch (Exception e) { e.printStackTrace(); } movdate.setLayoutParams( new LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); TextView movreason = new TextView(activity); Field field; try { field = (R.string.class.getField(reason)); movreason.setText(activity.getString(field.getInt(R.string.class))); } catch (SecurityException e) { } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } movreason.setPadding(0, 0, 0, 0); movreason.setTextColor(Color.parseColor("#545859")); movreason.setMaxLines(2); movreason.setTextSize(12); movreason.setLayoutParams( new LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); main.addView(appname); main.addView(movdate); main.addView(movreason); row.addView( main, new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); LinearLayout position = new LinearLayout(row.getContext()); position.setGravity(Gravity.CENTER); TextView movvalue = new TextView(activity); String textvalue; if (value > 0) textvalue = "+" + value; // String.format("%02d", (int)value); else textvalue = value.toString(); // String.format("%02d", (int)value); movvalue.setText(textvalue); movvalue.setPadding(0, 0, 0, 0); movvalue.setTextColor(Color.GRAY); movvalue.setTextSize(30); position.addView(movvalue); TableRow.LayoutParams params = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); params.setMargins(0, 0, 10, 0); row.addView(position, params); return row; }
@Override protected void onPostExecute(List<Action> actions) { if (actions == null) { statusLabel.setText("Unable to get actions"); return; } // all is ok, replace start pane LinearLayout contentPane = (LinearLayout) findViewById(R.id.contentPane); contentPane.removeView(startPane); LinearLayout buttonsLayout = new LinearLayout(getApplicationContext()); buttonsLayout.setGravity(Gravity.CENTER); TableLayout buttonsTable = new TableLayout(getApplicationContext()); TableRow currentTableRow = new TableRow(getApplicationContext()); TableRow.LayoutParams buttonMarginParams = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); int marginPx = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()); buttonMarginParams.setMargins(marginPx, marginPx, marginPx, marginPx); for (final Action action : actions) { ImageButton actionButton = new ImageButton(getApplicationContext()); int drawableId = getResources().getIdentifier(action.icon, "drawable", getPackageName()); actionButton.setImageDrawable(getResources().getDrawable(drawableId)); actionButton.setContentDescription(action.description); actionButton.setLayoutParams(buttonMarginParams); actionButton.setBackgroundResource(R.drawable.button); actionButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { new PerformActionAsyncTask().execute(action.name); } }); currentTableRow.addView(actionButton); if (currentTableRow.getChildCount() == 3) { buttonsTable.addView(currentTableRow); currentTableRow = new TableRow(getApplicationContext()); } } if (currentTableRow.getChildCount() > 0) { buttonsTable.addView(currentTableRow); } buttonsLayout.addView(buttonsTable); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); contentPane.addView(buttonsLayout, params); runStatusUpdateTimer(); }
private void createDataTable() { sqlite.openConnection(); ArrayList<Grafica> candidatos = sqlite.getCandidatos(); sqlite.closeConnection(); // TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams(); tableRowParams.setMargins(5, 3, 5, 3); tableRowParams.weight = 1; // encabezado TableRow rowHead = new TableRow(this); rowHead.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); // col 1 TextView col1 = new TextView(this); col1.setBackgroundResource(R.drawable.tv_bg); col1.setGravity(Gravity.CENTER); col1.setTypeface(null, Typeface.BOLD); col1.setTextSize(12); col1.setPadding(6, 10, 6, 10); col1.setText("TEMA"); // col 2 TextView col2 = new TextView(this); col2.setBackgroundResource(R.drawable.tv_bg); col2.setGravity(Gravity.CENTER); col2.setTypeface(null, Typeface.BOLD); col2.setTextSize(12); col2.setPadding(6, 10, 6, 10); col2.setText("LECCIÓN"); // col 3 TextView col3 = new TextView(this); col3.setBackgroundResource(R.drawable.tv_bg); col3.setGravity(Gravity.CENTER); col3.setTypeface(null, Typeface.BOLD); col3.setTextSize(12); col3.setPadding(6, 10, 6, 10); col3.setText("CALF"); // añade columnas rowHead.addView(col1, tableRowParams); rowHead.addView(col2, tableRowParams); rowHead.addView(col3, tableRowParams); // añade fila table_layout.addView(rowHead); for (Grafica c : candidatos) { TableRow row = new TableRow(this); row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); // col 1 TextView tv1 = new TextView(this); tv1.setBackgroundResource(R.drawable.tv_bg); tv1.setGravity(Gravity.CENTER); tv1.setTypeface(null, Typeface.BOLD); tv1.setTextSize(12); tv1.setPadding(6, 10, 6, 10); tv1.setText(c.getSigla()); // col 2 TextView tv2 = new TextView(this); tv2.setBackgroundResource(R.drawable.tv_bg); tv2.setGravity(Gravity.CENTER); tv2.setTextSize(12); tv2.setPadding(6, 10, 6, 10); tv2.setText(c.getNombre()); // col 3 TextView tv3 = new TextView(this); tv3.setBackgroundResource(R.drawable.tv_bg); tv3.setGravity(Gravity.CENTER); tv3.setTextSize(12); tv3.setPadding(6, 10, 6, 10); tv3.setText(String.valueOf(c.getVotos())); // añade columnas row.addView(tv1, tableRowParams); row.addView(tv2, tableRowParams); row.addView(tv3, tableRowParams); // añade fila table_layout.addView(row); } }
/** * Creates the actual minesweeper board as well as all Boxes. Sets up certain boxes as mines. * * @param frame2 tablerow to hold board * @param x number of rows * @param y number of columns * @param mines number of mines * @param context context of activity */ public void createBoard(ViewGroup frame2, int x, int y, int mines, MainActivity context) { TableLayout frame = (TableLayout) frame2; this.context = context; this.context.minesRemaining.setText(Integer.toString(mines)); this.x = x; this.y = y; this.mines = mines; this.boxesFilled = 0; this.isGoing = false; this.isPaused = false; int minesCreated = 0; this.board = new Box[x][y]; for (int i = 0; i < this.x; ++i) { TableRow row = new TableRow(context); int height = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, (float) 48.0, context.getResources().getDisplayMetrics()); TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, height); params.gravity = Gravity.CENTER; params.setMargins(0, 0, 0, 0); row.setLayoutParams(params); row.setOrientation(0); int padding = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, (float) -2, context.getResources().getDisplayMetrics()); row.setPadding(padding, padding, padding, padding); for (int j = 0; j < this.y; ++j) { this.board[i][j] = new Box(this, context); final int localI = i; final int localJ = j; final MainActivity newcontext = context; this.board[i][j].setOnClickListener( new OnClickListener() { public void onClick(View v) { final int result; if (newcontext.flagMode == 1) { result = flagIt(localI, localJ); } else { result = hitIt(localI, localJ); } getResult(result); } }); row.addView(this.board[i][j]); } frame.addView(row); } // use a while loop for more randomness while (minesCreated < this.mines) { Random r = new Random(); int i = r.nextInt(this.x); int j = r.nextInt(this.y); double rando = (((this.mines - minesCreated) / ((this.x * this.y) - ((i * this.y) + j) * 1.0)) * 10); int surroundingMines = this.getSurrounding(i, j); int temp = r.nextInt(10 - (surroundingMines / 2)); if (rando >= temp && this.board[i][j].isMine() == 0) { this.board[i][j].makeMine(); this.addSurrounding(i, j); minesCreated++; } } /*for (int i = 0; i < this.x; ++i) { for (int j = 0; j < this.y; ++j) { Random r = new Random(); double rando = (((this.mines-minesCreated) / ((this.x*this.y)-((i * this.y) + j)*1.0)) * 10); int surroundingMines = this.getSurrounding(i, j); int temp = r.nextInt(10-surroundingMines); if (rando >= temp && minesCreated < this.mines) { this.board[i][j].makeMine(); this.addSurrounding(i, j); minesCreated++; } } }*/ // zoom in and out code final Minesweeper ms2 = this; ImageView zoomOutButton = (ImageView) context.findViewById(R.id.zoomout); zoomOutButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { ms2.resizeMe(1); } }); ImageView zoomInButton = (ImageView) context.findViewById(R.id.zoomin); zoomInButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { ms2.resizeMe(0); } }); context.flagButton.setImageDrawable(context.getResources().getDrawable(R.drawable.mine)); context.flagMode = 0; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_card_add_user_hobby); Intent intent = getIntent(); String hobby = intent.getStringExtra(CardEditActivity.EDIT_HOBBY_STR); String[] hobbys = hobby.split(";|£º| "); Map<String, Boolean> hobbymap = new HashMap<String, Boolean>(); for (String item : hobbys) { hobbymap.put(item, false); } LayoutInflater inflater = LayoutInflater.from(CardAddUserHobbyActivity.this); TableLayout tl = (TableLayout) findViewById(R.id.tableLayout); this.width = DeviceInfoUtil.getDeviceCsw(getApplicationContext()); this.times = DeviceInfoUtil.getDeviceCsd(getApplicationContext()); padding = (int) (padding * times); baseMargin = (int) (baseMargin * times); int restWidth = width - 2 * padding - 3 * baseMargin; int widthOne = restWidth / 4; baseMargin = (int) ((restWidth - widthOne * 4) / 3) + baseMargin; tl.setPadding(padding, 0, padding, 0); String[] items = getResources().getStringArray(R.array.array_hobby); TableRow tr = null; for (int i = 0; i < items.length; i++) { if (i % 4 == 0) { tr = new TableRow(CardAddUserHobbyActivity.this); tl.addView(tr); } ToggleButton tb = (ToggleButton) inflater.inflate(R.layout.item_toggle, null); tb.setText(items[i]); tb.setTextOn(items[i]); tb.setTextOff(items[i]); tb.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { buttonView.setTextColor(Color.rgb(0, 72, 255)); selected.put(buttonView.getText().toString(), true); } else { buttonView.setTextColor(Color.rgb(52, 52, 52)); selected.put(buttonView.getText().toString(), false); } } }); tr.addView(tb); TableRow.LayoutParams trlp = new TableRow.LayoutParams(widthOne, TableRow.LayoutParams.WRAP_CONTENT); trlp.rightMargin = baseMargin; trlp.bottomMargin = baseMargin * 3 / 8; trlp.topMargin = baseMargin * 3 / 8; tb.setLayoutParams(trlp); if (hobbymap.containsKey(items[i])) { tb.setChecked(true); hobbymap.put(items[i], true); selected.put(items[i], true); } else { selected.put(items[i], false); } } String hobbyStr = ""; for (String item : hobbymap.keySet()) { if (!hobbymap.get(item)) { hobbyStr += item + " "; } } ((EditText) findViewById(R.id.editText)).setText(hobbyStr); initClick(); }
public void appendNeighborCellInfo(NeighboringCellInfo data) { TableRow tr = new TableRow(this); int color = Color.parseColor("#000000"); TextView label = new TextView(this); TableRow.LayoutParams params = new TableRow.LayoutParams(); params.span = 2; params.leftMargin = 10; params.rightMargin = 10; params.bottomMargin = 10; TableRow.LayoutParams params2 = new TableRow.LayoutParams(); params2.weight = 1; // params2.gravity=16; label.setLayoutParams(params); label.setText("Neighbor Cell Tower"); label.setTextSize(20); label.setTextColor(Color.parseColor("#909090")); // label.setTypeface(null, Typeface.BOLD); // label.setGravity(Gravity.CENTER); // label.setPadding(0, 10, 0, 0); tr.addView(label); tr.setLayoutParams(params); ((TableLayout) findViewById(R.id.info_table)).addView(tr, params); tr = new TableRow(this); label = new TextView(this); label.setLayoutParams(params); label.setText("Network type "); label.setTextSize(18); label.setTextColor(color); tr.setBackgroundResource(R.drawable.black_alpha); tr.addView(label); label = new TextView(this); label.setTextSize(18); label.setLayoutParams(params2); label.setText(getString(DCSConvertorUtil.networkTypeToStringId(data.getNetworkType()))); label.setTextColor(color); tr.addView(label); ((TableLayout) findViewById(R.id.info_table)).addView(tr, params); tr.setLayoutParams(params); tr = new TableRow(this); label = new TextView(this); label.setTextSize(18); label.setTextColor(color); tr.setBackgroundResource(R.drawable.black_alpha); label.setLayoutParams(params); label.setText("PSC "); tr.addView(label); label = new TextView(this); label.setText(data.getPsc() + ""); label.setLayoutParams(params2); label.setTextColor(color); tr.addView(label); ((TableLayout) findViewById(R.id.info_table)).addView(tr, params); tr.setLayoutParams(params); tr = new TableRow(this); label = new TextView(this); label.setLayoutParams(params); label.setText("Cell id "); label.setTextSize(18); label.setTextColor(color); tr.setBackgroundResource(R.drawable.black_alpha); tr.addView(label); label = new TextView(this); label.setLayoutParams(params); label.setText(data.getCid() + ""); label.setTextColor(color); label.setLayoutParams(params2); tr.addView(label); ((TableLayout) findViewById(R.id.info_table)).addView(tr, params); tr.setLayoutParams(params); tr = new TableRow(this); label = new TextView(this); label.setLayoutParams(params); label.setText("Area code "); label.setTextSize(18); label.setTextColor(color); tr.setBackgroundResource(R.drawable.black_alpha); tr.addView(label); label = new TextView(this); label.setText(data.getLac() + ""); label.setTextColor(color); label.setLayoutParams(params2); tr.addView(label); ((TableLayout) findViewById(R.id.info_table)).addView(tr, params); tr.setLayoutParams(params); tr = new TableRow(this); label = new TextView(this); label.setLayoutParams(params); label.setText("Signal Strength "); label.setTextSize(18); label.setTextColor(color); tr.setBackgroundResource(R.drawable.black_alpha); tr.addView(label); label = new TextView(this); label.setLayoutParams(params); label.setText(data.getRssi() + ""); label.setTextColor(color); label.setLayoutParams(params2); tr.addView(label); ((TableLayout) findViewById(R.id.info_table)).addView(tr, params); tr.setLayoutParams(params); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.contact_country_legislator_layout); LegislatorDB helper = new LegislatorDB(this); final SQLiteDatabase db = helper.getReadableDatabase(); // 查詢不分區立委名單 Cursor c = db.query( "LEGISLATOR_DATA", new String[] {"legislator_id", "legislator_name"}, "legislator_dist_id>2300", null, null, null, null); c.moveToFirst(); int colCount = 3; int dataCount = c.getCount(); int showedCount = 0; int reminder = dataCount % colCount; int rowCount = 0; if (reminder == 0) rowCount = dataCount / colCount; else rowCount = ((dataCount - reminder) / colCount) + 1; // 建立委員按鍵清單 TableLayout layout = (TableLayout) findViewById(R.id.tableLegislatorList); for (int rowS = 0; rowS < rowCount; rowS++) { TableRow tr = new TableRow(this); for (int colS = 0; colS < colCount; colS++) { if (showedCount < dataCount) { Button b = new Button(this); TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); params.weight = 1.0f; b.setLayoutParams(params); b.setTextSize(18); b.setText(c.getString(1)); final String theLegislatorId = c.getString(0); // 按下按鍵後進入該該委員資料頁面 b.setOnClickListener( new Button.OnClickListener() { public void onClick(View v) { Intent intent = new Intent( ShowCountryLegislatorActivity.this, ShowLegislatorDataActivity.class); intent.putExtra("LEGIST_ID", theLegislatorId); startActivity(intent); } }); tr.addView(b); c.moveToNext(); showedCount++; } } layout.addView(tr); } c.close(); db.close(); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final TabActivity activity = (TabActivity) getActivity(); menu = activity.getMenu(); View rootView = inflater.inflate(R.layout.menu_layout, container, false); ScrollView scroll = new ScrollView(getActivity().getApplicationContext()); TableLayout menulist = new TableLayout(getActivity().getApplicationContext()); TableRow.LayoutParams param = new TableRow.LayoutParams(); param.setMargins(0, 0, 15, 0); final String sid = "1"; int id = 0; for (Beverage beverage : menu) { if (beverage.getType().equals("bier")) { id++; TableRow row = new TableRow(getActivity().getApplicationContext()); TextView tekst = new TextView(getActivity().getApplicationContext()); tekst.setText(beverage.getName()); tekst.setLayoutParams(param); tekst.setId(Integer.parseInt(sid + id)); row.addView(tekst); Button plus = new Button(getActivity().getApplicationContext()); plus.setText("plus"); plus.setLayoutParams(param); plus.setId(id); plus.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { int id = v.getId(); TextView name = (TextView) getView().findViewById(Integer.parseInt(sid + id)); String naam = name.getText().toString(); String currentsaldo = activity.plus(naam); TextView total = (TextView) getView().findViewById(Integer.parseInt(sid + id + id)); total.setText("€ " + currentsaldo); activity.setTotal(); total.invalidate(); } }); row.addView(plus); Button min = new Button(getActivity().getApplicationContext()); min.setText("min"); min.setLayoutParams(param); min.setId(id); min.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { int id = v.getId(); TextView name = (TextView) getView().findViewById(Integer.parseInt(sid + id)); String naam = name.getText().toString(); String currentsaldo = activity.min(naam); TextView total = (TextView) getView().findViewById(Integer.parseInt(sid + id + id)); total.setText("€ " + currentsaldo); activity.setTotal(); total.invalidate(); } }); row.addView(min); TextView amount = new TextView(getActivity().getApplicationContext()); amount.setText("€" + beverage.getPrice()); amount.setLayoutParams(param); row.addView(amount); TextView total = new TextView(getActivity().getApplicationContext()); total.setLayoutParams(param); total.setText("€ 0.00"); total.setId(Integer.parseInt(sid + id + id)); row.addView(total); menulist.addView(row); } } scroll.setPadding(20, 5, 0, 5); scroll.addView(menulist); return scroll; }
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View view = getActivity().getLayoutInflater().inflate(R.layout.detalle_estacionamiento, null); TextView titulo = (TextView) view.findViewById(R.id.nombreEstacionamiento); desc = (TextView) view.findViewById(R.id.descripcionEstacionamiento); mComentarioView = (EditText) view.findViewById(R.id.comentario); horarios = (TableLayout) view.findViewById(R.id.horarios); comentarios = (Button) view.findViewById(R.id.comentarios); title = getArguments().getString("title"); if (getArguments().getString("descripcion") != null) { descripcion = getArguments().getString("descripcion"); } RatingBar puntaje = (RatingBar) view.findViewById(R.id.ratingBar); puntaje.setOnRatingBarChangeListener( new RatingBar.OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { if (fromUser) { checkFacebookSession(); puntajeActual = rating; mComentarioView.setVisibility(View.VISIBLE); desc.setVisibility(View.GONE); horarios.setVisibility(View.GONE); comentarios.setVisibility(View.GONE); } } }); puntajeActual = getArguments().getDouble("puntaje"); puntaje.setRating((float) puntajeActual); titulo.setText(title); desc.setText(descripcion); comentarios.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Intent verComentarios = new Intent(getContext(), VerComentariosActivity.class); verComentarios.putExtra( VerComentariosActivity.ARG_ID_ESTACIONAMIENTO, getArguments().getString("title")); startActivity(verComentarios); } }); for (Estacionamiento est : RecorridoHolder.getInstance().getEstacionamientos()) { if (est.getNombre().equals(title)) { for (Tarifa tarifa : est.getTarifas()) { TableRow newRow = new TableRow(getContext()); TextView vehiculo = new TextView(getContext()); TextView tarifaHora = new TextView(getContext()); TextView tarifaDia = new TextView(getContext()); TableRow.LayoutParams llp = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); llp.setMargins(12, 0, 0, 0); // llp.setMargins(left, top, right, bottom); vehiculo.setPadding(3, 3, 3, 3); vehiculo.setLayoutParams(llp); tarifaHora.setPadding(3, 3, 3, 3); tarifaHora.setLayoutParams(llp); tarifaDia.setPadding(3, 3, 3, 3); tarifaDia.setLayoutParams(llp); vehiculo.setText(tarifa.getDescripcion()); tarifaHora.setText("$" + tarifa.getPrecioHora()); tarifaDia.setText("$" + tarifa.getPrecioDia()); newRow.addView(vehiculo, 0); newRow.addView(tarifaHora, 1); newRow.addView(tarifaDia, 2); horarios.addView(newRow); } break; } } builder .setView(view) // Add action buttons .setPositiveButton( R.string.accept, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (mComentarioView.getVisibility() == View.VISIBLE) EstacionamientosServices.calificar( title, puntajeActual, mComentarioView.getText().toString(), User.getCurrentUser().getName()); } }); return builder.create(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.shopping_list_table); bReturn = (TextView) findViewById(R.id.bReturn); bReturn.setOnClickListener(this); TableLayout myTable = (TableLayout) findViewById(R.id.ListTable); List<Coupon> allCoupons = mDbHelper.getCouponsOfUser(Coupon.TABLE_LIST, Register.currentUsername); double total = 0.0; for (int i = 0; i < allCoupons.size(); i++) { TableRow items = new TableRow(this); TextView list_amount = new TextView(this); list_amount.setText(Integer.toString(allCoupons.get(i).getAmount())); list_amount.setTextColor(Color.BLACK); list_amount.setGravity(Gravity.CENTER_HORIZONTAL); list_amount.setTextSize(14); TextView list_item = new TextView(this); list_item.setText(allCoupons.get(i).getItemName()); list_item.setTypeface(Typeface.SERIF); list_item.setTextColor(Color.BLACK); list_item.setTextSize(14); TextView list_description = new TextView(this); list_description.setText(allCoupons.get(i).getDescription()); list_description.setTypeface(Typeface.SERIF); list_description.setTextColor(Color.BLACK); list_description.setTextSize(14); TextView list_price = new TextView(this); list_price.setText(Double.toString(allCoupons.get(i).getItemPrice())); list_price.setTypeface(Typeface.SERIF); list_price.setTextColor(Color.BLACK); list_price.setGravity(Gravity.CENTER_HORIZONTAL); list_price.setTextSize(14); items.addView(list_amount); items.addView(list_item); items.addView(list_description); items.addView(list_price); myTable.addView(items); total += allCoupons.get(i).getItemPrice() * allCoupons.get(i).getAmount(); } TableRow rowTotal = new TableRow(this); TextView labelTotal = new TextView(this); labelTotal.setText("Total"); labelTotal.setTextSize(18); labelTotal.setTextColor(Color.BLACK); labelTotal.setPadding(10, 0, 0, 0); TableRow.LayoutParams params = new TableRow.LayoutParams(); params.span = 3; TextView DisplayTotal = new TextView(this); double number = Math.round(total * 100); number = number / 100; DisplayTotal.setText(Double.toString(number)); DisplayTotal.setTextSize(18); DisplayTotal.setGravity(Gravity.CENTER_HORIZONTAL); DisplayTotal.setTextColor(Color.BLACK); rowTotal.addView(labelTotal, params); rowTotal.addView(DisplayTotal); myTable.addView(rowTotal); }
protected void resizeContent(final int screenWidth, final int screenHeight) { if (null == game) throw new IllegalStateException(this + " must be initialized with onCreate()"); final float imageRatio = game.isImageSelected() ? game.getImageAspectRatio() : 1f; final int boardSize = getBoardSize(); final DisplayMetrics metrics = getResources().getDisplayMetrics(); // border width 1 dp rounded up to nearest whole pixels final int borderWidth = (int) Math.ceil(metrics.density); // calculate spacing allotment final int spacing = borderWidth * 2 * boardSize; if (screenWidth < spacing + boardSize || screenHeight < spacing + boardSize) throw new UnsupportedOperationException( "Screen size (" + screenWidth + " x " + screenHeight + ") too small for a board of " + boardSize + " rows"); final float adjustedScreenRatio = (float) (screenWidth - spacing) / (screenHeight - spacing); int width, height; if (adjustedScreenRatio > imageRatio) { // scale to screen height height = screenHeight; // fix width = imageRatio * height width = (int) (imageRatio * height); if (width < spacing + boardSize) throw new UnsupportedOperationException( "Need a wider image to make a board: scaled to " + width + " pixels, need " + (spacing + boardSize)); } else { // scale to screen width width = screenWidth; // fix height = width / imageRatio height = (int) (width / imageRatio); if (height < spacing + boardSize) throw new UnsupportedOperationException( "Need a taller image to make a board: scaled to " + height + " pixels, need " + (spacing + boardSize)); } // make the dimensions divisible by row/column count height -= height % boardSize; width -= width % boardSize; RelativeLayout.LayoutParams boardLayoutParams = new RelativeLayout.LayoutParams(width, height); boardLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); numericBoardView.setLayoutParams(boardLayoutParams); imageBoardView.setLayoutParams(boardLayoutParams); // load and resize the image width = width / boardSize - 2 * borderWidth; height = height / boardSize - 2 * borderWidth; game.setTileSize(width, height); if (game.isImageSelected()) try { game.loadImage(this); } catch (ImageProcessingException failure) { game.resetSelectedImage(); Log.e(getClass().getName(), failure.getMessage(), failure); hideBoard(); alert(R.string.image_load_error); return; } // size and fill cell views TableRow.LayoutParams cellParams = new TableRow.LayoutParams(width, height); cellParams.setMargins(borderWidth, borderWidth, borderWidth, borderWidth); float fontSize = width * 4f / 3; if (fontSize > height) fontSize = height; fontSize *= .5f; final Board board = getBoardModel(); for (int i = 0; i < boardSize; i++) { for (int j = 0; j < boardSize; j++) { TextView numericCell = numericCells[i][j]; numericCell.setLayoutParams(cellParams); numericCell.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize); ImageView imageCell = imageCells[i][j]; imageCell.setLayoutParams(cellParams); Tile tile = board.getTileAt(i, j); assignTile(numericCell, tile); assignTile(imageCell, tile); } } countDownCell.setLayoutParams(cellParams); countDownCell.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize); }
/** * 创建BallTable * * @param LinearLayout aParentView 上一级Layout * @param int aLayoutId 当前BallTable的LayoutId * @param int aFieldWidth BallTable区域的宽度(如屏幕宽度) * @param int aBallNum 小球个数 * @param int aBallViewWidth 小球视图的宽度(图片宽度) * @param int[] aResId 小球图片Id * @param int aIdStart 小球Id起始数值 * @param int aBallViewText 0:小球从0开始显示,1:小球从1开始显示 ,3小球从3开始显示(福彩3D和值组6从3开始) * @return BallTable */ private BallTable makeBallTable( LinearLayout aParentView, int aLayoutId, int aFieldWidth, int aBallNum, int[] aResId, int aIdStart, int aBallViewText) { BallTable iBallTable = new BallTable(aParentView, aLayoutId, aIdStart); int iBallNum = aBallNum; int iFieldWidth = aFieldWidth; int scrollBarWidth = 6; // 定义没行小球的个数为7 int viewNumPerLine = 7; int iBallViewWidth = (iFieldWidth - scrollBarWidth) / viewNumPerLine - 2; int lineNum = iBallNum / viewNumPerLine; int lastLineViewNum = iBallNum % viewNumPerLine; int margin = (iFieldWidth - scrollBarWidth - (iBallViewWidth + 2) * viewNumPerLine) / 2; int iBallViewNo = 0; for (int row = 0; row < lineNum; row++) { TableRow tableRow = new TableRow(aParentView.getContext()); for (int col = 0; col < viewNumPerLine; col++) { String iStrTemp = ""; if (aBallViewText == 0) { iStrTemp = "" + (iBallViewNo); // 小球从0开始 } else if (aBallViewText == 1) { iStrTemp = "" + (iBallViewNo + 1); // 小球从1开始 } else if (aBallViewText == 3) { iStrTemp = "" + (iBallViewNo + 3); // 小球从3开始 } OneBallView tempBallView = new OneBallView(aParentView.getContext()); tempBallView.setId(aIdStart + iBallViewNo); tempBallView.initBall(iBallViewWidth, iBallViewWidth, iStrTemp, aResId); tempBallView.setOnClickListener(this); iBallTable.addBallView(tempBallView); TableRow.LayoutParams lp = new TableRow.LayoutParams(); if (col == 0) { lp.setMargins(margin + 1, 1, 1, 1); } else if (col == viewNumPerLine - 1) { lp.setMargins(1, 1, margin + scrollBarWidth + 1, 1); } else lp.setMargins(1, 1, 1, 1); tableRow.addView(tempBallView, lp); iBallViewNo++; } // 新建的TableRow添加到TableLayout iBallTable.tableLayout.addView(tableRow, new TableLayout.LayoutParams(FP, WC)); } if (lastLineViewNum > 0) { TableRow tableRow = new TableRow(this); for (int col = 0; col < lastLineViewNum; col++) { String iStrTemp = ""; if (aBallViewText == 0) { iStrTemp = "" + (iBallViewNo); // 小球从0开始 } else if (aBallViewText == 1) { iStrTemp = "" + (iBallViewNo + 1); // 小球从1开始 } else if (aBallViewText == 3) { iStrTemp = "" + (iBallViewNo + 3); // 小球从3开始 } OneBallView tempBallView = new OneBallView(aParentView.getContext()); tempBallView.setId(aIdStart + iBallViewNo); tempBallView.initBall(iBallViewWidth, iBallViewWidth, iStrTemp, aResId); tempBallView.setOnClickListener(this); iBallTable.addBallView(tempBallView); TableRow.LayoutParams lp = new TableRow.LayoutParams(); if (col == 0) { lp.setMargins(margin + 1, 1, 1, 1); } else lp.setMargins(1, 1, 1, 1); tableRow.addView(tempBallView, lp); iBallViewNo++; } // 新建的TableRow添加到TableLayout iBallTable.tableLayout.addView(tableRow, new TableLayout.LayoutParams(FP, WC)); } return iBallTable; }
@Override public BallTable makeBallTable( TableLayout tableLayout, int aFieldWidth, int aBallNum, int[] aResId, int aIdStart, int aBallViewText, Context context, OnClickListener onclick) { TableLayout tabble = tableLayout; BallTable iBallTable = new BallTable(aIdStart, context); int iBallNum = aBallNum; int viewNumPerLine = 8; // 定义没行小球的个数为7 int iFieldWidth = aFieldWidth; int scrollBarWidth = 6; int iBallViewWidth = (iFieldWidth - scrollBarWidth) / viewNumPerLine - 2; int lineNum = iBallNum / viewNumPerLine; int lastLineViewNum = iBallNum % viewNumPerLine; int margin = (iFieldWidth - scrollBarWidth - (iBallViewWidth + 2) * viewNumPerLine) / 2; int iBallViewNo = 0; for (int row = 0; row < lineNum; row++) { TableRow tableRow = new TableRow(context); for (int col = 0; col < viewNumPerLine; col++) { String iStrTemp = ""; switch (col) { case 0: iStrTemp = "大"; break; case 1: iStrTemp = "小"; break; case 2: iStrTemp = "单"; break; case 3: iStrTemp = "双"; break; } OneBallView tempBallView = new OneBallView(context); tempBallView.setId(aIdStart + iBallViewNo); tempBallView.initBall(iBallViewWidth, iBallViewWidth, iStrTemp, aResId); tempBallView.setOnClickListener(onclick); iBallTable.addBallView(tempBallView); TableRow.LayoutParams lp = new TableRow.LayoutParams(); if (col == 0) { lp.setMargins(margin, 1, 1, 1); } else if (col == viewNumPerLine - 1) { lp.setMargins(1, 1, margin + scrollBarWidth + 1, 1); } else lp.setMargins(1, 1, 1, 1); tableRow.addView(tempBallView, lp); iBallViewNo++; } tabble.addView(tableRow, new TableLayout.LayoutParams(PublicConst.FP, PublicConst.WC)); } if (lastLineViewNum > 0) { TableRow tableRow = new TableRow(context); for (int col = 0; col < lastLineViewNum; col++) { String iStrTemp = ""; switch (col) { case 0: iStrTemp = "大"; break; case 1: iStrTemp = "小"; break; case 2: iStrTemp = "单"; break; case 3: iStrTemp = "双"; break; } OneBallView tempBallView = new OneBallView(context); tempBallView.setId(aIdStart + iBallViewNo); tempBallView.initBall(iBallViewWidth, iBallViewWidth, iStrTemp, aResId); tempBallView.setOnClickListener(onclick); iBallTable.addBallView(tempBallView); TableRow.LayoutParams lp = new TableRow.LayoutParams(); if (col == 0) { lp.setMargins(margin, 1, 1, 1); } else lp.setMargins(1, 1, 1, 1); tableRow.addView(tempBallView, lp); iBallViewNo++; } // 新建的TableRow添加到TableLayout tabble.addView(tableRow, new TableLayout.LayoutParams(PublicConst.FP, PublicConst.WC)); } return iBallTable; }
private TableLayout getTable(Trigger trigger) { WindowManager mWinMgr = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); int displayWidth = mWinMgr.getDefaultDisplay().getWidth(); TextView description = new TextView(ctx); description.setText(trigger.getDescription()); description.setTextColor(Color.BLACK); description.setTextSize(16); TextView hostName = new TextView(ctx); hostName.setText(trigger.getHost()); hostName.setTextColor(Color.BLACK); hostName.setTextSize(14); TextView age = new TextView(ctx); age.setText(trigger.getAgeTime()); age.setTextColor(Color.DKGRAY); age.setTextSize(12); age.setPadding(0, 10, 0, 0); // ##############################################################################3 TableLayout table = new TableLayout(ctx); // ##############################################################################3 TableRow row1 = new TableRow(ctx); if (!showage()) { TableRow.LayoutParams hostNameparam = new TableRow.LayoutParams(displayWidth / 2, LayoutParams.WRAP_CONTENT); hostNameparam.gravity = Gravity.LEFT; row1.addView(hostName, hostNameparam); TableRow.LayoutParams ageparam = new TableRow.LayoutParams(displayWidth / 3, LayoutParams.WRAP_CONTENT); ageparam.gravity = Gravity.RIGHT; row1.addView(age, ageparam); } else { TableRow.LayoutParams hostNameparam = new TableRow.LayoutParams(displayWidth - 40, LayoutParams.WRAP_CONTENT); hostNameparam.gravity = Gravity.LEFT; row1.addView(hostName, hostNameparam); } table.addView(row1, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); // ##############################################################################3 TableRow row2 = new TableRow(ctx); LinearLayout descripionLayout = new LinearLayout(ctx); TableRow.LayoutParams params = new TableRow.LayoutParams(); params.span = 2; descripionLayout.addView(description); descripionLayout.setLayoutParams(params); row2.addView(descripionLayout); table.addView(row2); return table; }