use of android.widget.Space in project Rashr by DsLNeXuS.
the class CardUI method refresh.
//suppress this error message to be able to use spaces in higher api levels
@SuppressLint("NewApi")
public void refresh() {
if (mAdapter == null) {
mAdapter = new StackAdapter(mContext, mStacks, mSwipeable);
if (mListView != null) {
mListView.setAdapter(mAdapter);
} else if (mTableLayout != null) {
TableRow tr = null;
for (int i = 0; i < mAdapter.getCount(); i += mColumnNumber) {
//add a new table row with the current context
tr = new TableRow(mTableLayout.getContext());
tr.setOrientation(TableRow.HORIZONTAL);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
//add as many cards as the number of columns indicates per row
for (int j = 0; j < mColumnNumber; j++) {
if (i + j < mAdapter.getCount()) {
View card = mAdapter.getView(i + j, null, tr);
if (card.getLayoutParams() != null) {
card.setLayoutParams(new TableRow.LayoutParams(card.getLayoutParams().width, card.getLayoutParams().height, 1f));
} else {
card.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
}
tr.addView(card);
}
}
mTableLayout.addView(tr);
}
if (tr != null) {
//fill the empty space with spacers
for (int j = mAdapter.getCount() % mColumnNumber; j > 0; j--) {
View space = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
space = new Space(tr.getContext());
} else {
space = new View(tr.getContext());
}
space.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
tr.addView(space);
}
}
}
} else {
// in case swipeable changed;
mAdapter.setSwipeable(mSwipeable);
mAdapter.setItems(mStacks);
}
}
use of android.widget.Space in project android_frameworks_base by ResurrectionRemix.
the class BiDiTestGridLayoutCodeLtr method create.
public static View create(Context context) {
GridLayout layout = new GridLayout(context);
layout.setUseDefaultMargins(true);
layout.setAlignmentMode(ALIGN_BOUNDS);
layout.setRowOrderPreserved(false);
layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
Spec row1 = spec(0);
Spec row2 = spec(1);
Spec row3 = spec(2, BASELINE);
Spec row4 = spec(3, BASELINE);
// allow the last two rows to overlap the middle two
Spec row5 = spec(2, 3, FILL);
Spec row6 = spec(5);
Spec row7 = spec(6);
Spec col1a = spec(0, 4, CENTER);
Spec col1b = spec(0, 4, LEFT);
Spec col1c = spec(0, RIGHT);
Spec col2 = spec(1, START);
Spec col3 = spec(2, FILL);
Spec col4a = spec(3);
Spec col4b = spec(3, FILL);
{
TextView c = new TextView(context);
c.setTextSize(32);
c.setText("Email setup");
layout.addView(c, new GridLayout.LayoutParams(row1, col1a));
}
{
TextView c = new TextView(context);
c.setTextSize(16);
c.setText("You can configure email in just a few steps:");
layout.addView(c, new GridLayout.LayoutParams(row2, col1b));
}
{
TextView c = new TextView(context);
c.setText("Email address:");
layout.addView(c, new GridLayout.LayoutParams(row3, col1c));
}
{
EditText c = new EditText(context);
c.setEms(10);
c.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
layout.addView(c, new GridLayout.LayoutParams(row3, col2));
}
{
TextView c = new TextView(context);
c.setText("Password:");
layout.addView(c, new GridLayout.LayoutParams(row4, col1c));
}
{
TextView c = new EditText(context);
c.setEms(8);
c.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD);
layout.addView(c, new GridLayout.LayoutParams(row4, col2));
}
{
Space c = new Space(context);
layout.addView(c, new GridLayout.LayoutParams(row5, col3));
}
{
Button c = new Button(context);
c.setText("Manual setup");
layout.addView(c, new GridLayout.LayoutParams(row6, col4a));
}
{
Button c = new Button(context);
c.setText("Next");
layout.addView(c, new GridLayout.LayoutParams(row7, col4b));
}
return layout;
}
Aggregations