Example usage for android.widget LinearLayout addView

List of usage examples for android.widget LinearLayout addView

Introduction

In this page you can find the example usage for android.widget LinearLayout addView.

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.hbm.devices.scan.ui.android.DetailsFiller.java

private void addRule(LinearLayout layout) {
    final View rule = new View(activity);
    final LinearLayout.LayoutParams viewLp = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT,
            activity.getResources().getDimensionPixelSize(R.dimen.rule_height));
    viewLp.setMargins(activity.getResources().getDimensionPixelSize(R.dimen.device_info_padding_left),
            activity.getResources().getDimensionPixelSize(R.dimen.device_info_padding_top), 0, 0);
    rule.setLayoutParams(viewLp);/*from w  w w.jav a2 s .co m*/
    rule.setBackgroundColor(ContextCompat.getColor(activity, R.color.details_horizontal_rule_color));
    layout.addView(rule);
}

From source file:com.google.sample.beaconservice.ManageBeaconFragment.java

private LinearLayout makeAttachmentRow(JSONObject attachment) throws JSONException {
    LinearLayout row = new LinearLayout(getActivity());
    int id = View.generateViewId();
    row.setId(id);//from w  w  w  .j av a  2 s. c  o m
    String[] namespacedType = attachment.getString("namespacedType").split("/");
    row.addView(makeTextView(namespacedType[0]));
    row.addView(makeTextView(namespacedType[1]));
    String dataStr = attachment.getString("data");
    String base64Decoded = new String(Utils.base64Decode(dataStr));
    row.addView(makeTextView(base64Decoded));
    row.addView(createAttachmentDeleteButton(id, attachment.getString("attachmentName")));
    return row;
}

From source file:com.krg.ParallaxScrollView.sample.PagerViewBackgroundActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create ParallaxScrollView, which will eventually be the container for everything.
    ParallaxScrollView parallaxScrollView = new ParallaxScrollView(this);
    parallaxScrollView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // Create the Background View, a ViewPager.
    ViewPager backgroundViewPager = new ViewPager(this);
    backgroundViewPager.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 600));
    ImageAdapter adapter = new ImageAdapter(this);
    backgroundViewPager.setAdapter(adapter);

    // Create the Contents View.
    LinearLayout contentView = new LinearLayout(this);
    contentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    contentView.setBackgroundColor(0xffffffff);
    int padding = getResources().getDimensionPixelSize(R.dimen.content_padding);
    contentView.setPadding(padding, padding, padding, padding);
    TextView textView = new TextView(this);
    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    textView.setText(R.string.starry_night);
    float textSize = getResources().getDimension(R.dimen.content_text_size);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    contentView.addView(textView);

    // Make the ParallaxScrollView aware of the Background, Content, and Header Views, and set the content of
    // this view to the ParallaxScrollView.
    parallaxScrollView.setBackgroundView(backgroundViewPager);
    parallaxScrollView.setContentView(contentView);
    setContentView(parallaxScrollView);//from   w  w  w . j  av a 2  s .  co m
}

From source file:com.androcast.illusion.illusionmod.MainActivity.java

/**
 * Dialog which asks the user to enter his password
 *
 * @param password current encoded password
 *//*from w  w  w  .  j  a  va2s .c  o m*/
private void askPassword(final String password) {
    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    linearLayout.setPadding(30, 20, 30, 20);

    final AppCompatEditText mPassword = new AppCompatEditText(this);
    mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    mPassword.setHint(getString(R.string.password));
    linearLayout.addView(mPassword);

    new AlertDialog.Builder(this).setView(linearLayout).setCancelable(false)
            .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (mPassword.getText().toString().equals(Utils.decodeString(password)))
                        new Task().execute();
                    else {
                        Utils.toast(getString(R.string.password_wrong), MainActivity.this);
                        finish();
                    }
                }
            }).show();
}

From source file:com.houseofslack.pullscoring.Scoring.java

private void redrawOneSetOfScores(LinearLayout layout, List<Integer> scores, int scoreLayoutId,
        int scrollLayoutId, String teamName, int teamAndScoreId) {
    LayoutInflater inflater = getLayoutInflater();
    layout.removeAllViews();/*from ww w  .j a v  a 2s  .  c o m*/
    int totalScore = 0;
    for (int score : scores) {
        totalScore += score;
        TextView textView = (TextView) inflater.inflate(scoreLayoutId, null);
        textView.setText(String.valueOf(score));
        layout.addView(textView);
    }
    TextView textView = (TextView) findViewById(teamAndScoreId);
    textView.setText(getString(R.string.total_score, teamName, totalScore));
    // set the scroll view to the bottom of the display
    final ScrollView scrollView = (ScrollView) findViewById(scrollLayoutId);
    scrollView.post(new Runnable() {
        @Override
        public void run() {
            scrollView.fullScroll(ScrollView.FOCUS_DOWN);
        }
    });
}

From source file:com.google.sample.beaconservice.ManageBeaconFragment.java

private LinearLayout makeAttachmentInsertRow() {
    LinearLayout insertRow = new LinearLayout(getActivity());
    final TextView namespaceTextView = makeTextView(namespace);
    final EditText typeEditText = makeEditText();
    final EditText dataEditText = makeEditText();

    insertRow.addView(namespaceTextView);
    insertRow.addView(typeEditText);/*from  w  w w  . ja va 2s  .  c om*/
    insertRow.addView(dataEditText);

    Button insertButton = new Button(getActivity());
    insertButton.setText("+");
    insertButton.setLayoutParams(BUTTON_COL_LAYOUT);
    insertButton.setOnClickListener(
            makeInsertAttachmentOnClickListener(insertButton, namespaceTextView, typeEditText, dataEditText));

    insertRow.addView(insertButton);
    return insertRow;
}

From source file:com.jhk.whysoformal.activity.musiclist.fragment.MusicListFragment.java

private void showItemWeightPopUp() {
    if (mItemWeight == null) {
        mItemWeight = new PopupWindow(getListView());

        View view = getActivity().getLayoutInflater().inflate(R.layout.popup_weight_distribution, null);
        LinearLayout distributionLayout = (LinearLayout) view.findViewById(R.id.distributionLayout);
        Context ctx = mItemWeight.getContentView().getContext();

        BaseSeries data = new BaseSeries(getString(R.string.weight_distribution),
                new float[][] { new float[] { 0.0f, 2.0f }, new float[] { 1.0f, 1.0f },
                        new float[] { 2.0f, 1.0f }, new float[] { 3.0f, 1.0f }, new float[] { 4.0f, 1.0f } },
                10, new GraphStyleAttributes(Color.BLUE, 20f, 3f));
        List<BaseSeries> entries = new LinkedList<BaseSeries>();
        entries.add(data);//from  w  ww .  jav a 2 s  .  c om

        distributionLayout.addView(new GraphView(ctx, entries, getString(R.string.distribute_me),
                new BaseAxis(0, 4, 1, 10, GraphStyleAttributes.sDEFAULT_X_AXIS_LABEL_STYLE_ATTRIBUTES),
                new BaseAxis(0, 2, 1, 10, GraphStyleAttributes.sDEFAULT_Y_AXIS_LABEL_STYLE_ATTRIBUTES)));

        view.invalidate();
        Button okayButton = (Button) view.findViewById(R.id.weight_distribution_ok_button);
        okayButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mItemWeight.dismiss();
            }
        });

        mItemWeight.setFocusable(true);
        mItemWeight.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
        mItemWeight.setHeight(600);
        mItemWeight.setContentView(view);
    }

    mItemWeight.showAtLocation(getListView(), Gravity.CENTER, 0, 0);
}

From source file:com.googlecode.android_scripting.activity.Main.java

protected void initializeViews() {
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    layout.setGravity(Gravity.CENTER_HORIZONTAL);
    TextView textview = new TextView(this);
    textview.setText(" PhpForAndroid " + version);
    ImageView imageView = new ImageView(this);
    imageView.setImageDrawable(getResources().getDrawable(R.drawable.pfa));
    layout.addView(imageView);
    mButton = new Button(this);
    mAboutButton = new Button(this);
    MarginLayoutParams marginParams = new MarginLayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);//  ww  w.  j ava  2s .c  o m
    final float scale = getResources().getDisplayMetrics().density;
    int marginPixels = (int) (MARGIN_DIP * scale + 0.5f);
    marginParams.setMargins(marginPixels, marginPixels, marginPixels, marginPixels);
    mButton.setLayoutParams(marginParams);
    mAboutButton.setLayoutParams(marginParams);
    layout.addView(textview);
    layout.addView(mButton);
    layout.addView(mAboutButton);

    mProgressLayout = new LinearLayout(this);
    mProgressLayout.setOrientation(LinearLayout.HORIZONTAL);
    mProgressLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    mProgressLayout.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);

    LinearLayout bottom = new LinearLayout(this);
    bottom.setOrientation(LinearLayout.HORIZONTAL);
    bottom.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    bottom.setGravity(Gravity.CENTER_VERTICAL);
    mProgressLayout.addView(bottom);

    TextView message = new TextView(this);
    message.setText("   In Progress...");
    message.setTextSize(20);
    message.setTypeface(Typeface.DEFAULT_BOLD);
    message.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    ProgressBar bar = new ProgressBar(this);
    bar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    bottom.addView(bar);
    bottom.addView(message);
    mProgressLayout.setVisibility(View.INVISIBLE);

    layout.addView(mProgressLayout);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setProgressBarIndeterminateVisibility(false);

    setContentView(layout);
}

From source file:gov.in.bloomington.georeporter.fragments.ReportFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    TextView service_description = (TextView) getView().findViewById(R.id.service_description);
    service_description.setText(mService.optString(Open311.DESCRIPTION));

    // Inflate all the views for the service attributes
    if (mService.optBoolean(Open311.METADATA)) {
        LinearLayout layout = (LinearLayout) getView().findViewById(R.id.attributes);
        JSONObject definition = Open311.sServiceDefinitions.get(mService.opt(Open311.SERVICE_CODE));
        JSONArray attributes = definition.optJSONArray(Open311.ATTRIBUTES);

        int len = attributes.length();
        for (int i = 0; i < len; i++) {
            JSONObject a = attributes.optJSONObject(i);

            View v = loadViewForAttribute(a, savedInstanceState);
            if (v != null) {
                String description = a.optString(Open311.DESCRIPTION);
                TextView label = (TextView) v.findViewById(R.id.label);
                label.setText(description);

                layout.addView(v);
            }//from  ww  w  . j av a2  s.  co m
        }
    }
}

From source file:com.appfirst.activities.details.AFServerDetail.java

/**
 * Draw a ScrollView to display the Disk busy for each disk.
 * /*  w  w w .j ava2 s.c  o m*/
 * @return a ScrollView containing a list of AFBarView and AFPieView.
 */
private View createDiskBusyListDialog() {
    ScrollView container = createOuterContainer();

    LinearLayout innerContainer = createInnerContainer();

    List<BasicNameValuePair> items = data.getDisk_busy();
    for (int i = 0; i < items.size(); i++) {
        BasicNameValuePair item = items.get(i);
        Double value = 0.0;
        try {
            value = Double.parseDouble(item.getValue());
        } catch (Exception e) {
            e.printStackTrace();
            continue;
        }
        String name = item.getName();
        LinearLayout row = createTableRow(LinearLayout.VERTICAL);
        TextView text = new TextView(this);
        text.setPadding(5, 0, 0, 0);
        text.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        text.setText(name);
        AFBarView barView = createBarView(value);

        row.addView(barView);
        row.addView(text);
        innerContainer.addView(row);
    }
    container.addView(innerContainer);
    innerContainer.invalidate();
    container.invalidate();
    return container;
}