Example usage for android.widget RelativeLayout addView

List of usage examples for android.widget RelativeLayout addView

Introduction

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

Prototype

public void addView(View child, int index) 

Source Link

Document

Adds a child view.

Usage

From source file:Main.java

public static void AddView(RelativeLayout panel, View v, int vw, int vh, int styles[][], int left, int top) {
    panel.addView(v, GetRLP(vw, vh, styles, left, top));
}

From source file:Main.java

/**
 * //from ww w  .j ava 2  s.c o  m
 * @param panel
 * @param v
 * @param vw
 * @param vh
 * @param styles
 * @param left
 * @param top
 */
public static void AddView(RelativeLayout panel, View v, int vw, int vh, int styles[][], int left, int top) {
    panel.addView(v, GetRLP(vw, vh, styles, left, top));
}

From source file:com.gigigo.vuforiaimplementation.VuforiaActivity.java

@Override
public void setContentViewTop(View vuforiaView) {

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.activity_vuforia, null);
    scanLine = view.findViewById(R.id.scan_line);
    RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.layoutContentVuforiaGL);
    relativeLayout.addView(vuforiaView, 0);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)

        markFakeFeaturePoint = new MarkFakeFeaturePoint(this);
    relativeLayout.addView(markFakeFeaturePoint);
    ViewGroup.LayoutParams vlp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);

    addContentView(view, vlp);/*w w w. ja v  a 2  s.com*/

    //region Button Close
    view.findViewById(R.id.btnCloseVuforia).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
    //endregion
    mVuforiaView = vuforiaView;
    setThemeColorScheme();

    startBoringAnimation();
    scanlineStart();

}

From source file:com.gigigo.imagerecognition.vuforia.VuforiaActivity.java

@Override
public void setContentViewTop(View vuforiaView) {

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.ir_activity_vuforia, null);
    scanLine = view.findViewById(R.id.scan_line);
    RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.layoutContentVuforiaGL);
    relativeLayout.addView(vuforiaView, 0);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)

        markFakeFeaturePoint = new MarkFakeFeaturePoint(this);
    relativeLayout.addView(markFakeFeaturePoint);
    ViewGroup.LayoutParams vlp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);

    addContentView(view, vlp);//www .j a  va  2s  .  c  o m

    //region Button Close
    view.findViewById(R.id.btnCloseVuforia).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent i = new Intent();
            i.putExtra(ImageRecognitionConstants.VUFORIA_PATTERN_ID, "");
            setResult(Activity.RESULT_CANCELED, i);
            finish();

        }
    });
    //endregion
    mVuforiaView = vuforiaView;
    setThemeColorScheme();

    startBoringAnimation();
    scanlineStart();

}

From source file:com.keifermiller.inkbar.activities.IBActivity.java

@Override
public void setContentView(View view, LayoutParams params) {
    RelativeLayout iBContent = (RelativeLayout) View.inflate(this, R.layout.ib_activity_layout, null);
    iBContent.addView(view, params);
    super.setContentView(iBContent);
}

From source file:fm.krui.kruifm.ScheduleFragment.java

/**
 * Adds a show to the schedule./*from  ww  w. j av  a 2  s  .co m*/
 * @param title Title of show to display
 * @param description Description of show to display
 * @param startTime Start time of show in minutes from midnight
 * @param endTime End time of show in minutes from midnight
 * @param category Format of this show, required to correctly color the event.
 *
 * Valid settings for category include:
 *                 1 - Regular Rotation
 *                 2 - Music Speciality
 *                 3 - Sports
 *                 4 - News/Talk
 *                 5 - Specials
 */
private void addShow(String title, String description, int startTime, int endTime, int category) {

    /* Build the LinearLayout to function as the container for this show. Since the size of the container is to represent
    the length of the show, its height must be proportional (1dp = 1 minute) to the length. Determine length by finding the difference
    between the start and end times. */

    // Fix for corner case of shows ending at midnight.
    if (endTime == 0) {
        endTime = 1440;
    }
    int difference = endTime - startTime;

    /* Define the margins of this show. All shows must not overlap the displayed times, which are 50dp in width.
    Add 5 more (to the right and left) to see the schedule lines for clarity. Push the show down to align with the appropriate time marker using the top margin value set to the
    difference (in minutes) between midnight and the start of the show. */

    Log.v(TAG, "Configuring " + title);
    //Log.v(TAG, "Start time: " + startTime + " End time: " + endTime);
    //Log.v(TAG, "Setting parameters for " + title);
    RelativeLayout.LayoutParams rrLayoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, dpToPixels(difference));
    rrLayoutParams.leftMargin = dpToPixels(55);
    //Log.v(TAG, "Left margin: " + rrLayoutParams.leftMargin);
    rrLayoutParams.topMargin = dpToPixels(startTime);
    //Log.v(TAG, "Top margin: " + rrLayoutParams.topMargin);
    rrLayoutParams.rightMargin = dpToPixels(5);
    //Log.v(TAG, "Right margin: " + rrLayoutParams.rightMargin);

    /* Build LinearLayout and apply parameters */
    LinearLayout eventLL = new LinearLayout(getActivity());
    eventLL.setOrientation(LinearLayout.VERTICAL);
    eventLL.setPadding(dpToPixels(5), dpToPixels(2), dpToPixels(5), dpToPixels(5));

    // Get background for this event
    eventLL.setBackgroundResource(getEventBackground(category));

    /* Add title of event to LinearLayout */
    TextView titleTV = new TextView(getActivity());

    // Title of a show should be bolded
    titleTV.setText(title);
    titleTV.setTypeface(null, Typeface.BOLD);
    titleTV.setPadding(dpToPixels(5), 0, dpToPixels(5), 0);
    eventLL.addView(titleTV);

    /* Determine length of event to see if we have room to attach a description (if one was passed) */
    int length = endTime - startTime;

    /* Attach a description with a size that depends on the event length (longer events can hold more description text). */
    if (description != null) {
        TextView descriptionTV = new TextView(getActivity());
        descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5));
        descriptionTV.setText(description);

        // ~hour long shows can display 1 line of description
        if (difference >= 30 && difference <= 60) {
            descriptionTV.setMaxLines(1);
        }

        // 1:30 long shows can display 2 lines of description
        else if (difference >= 60 && difference <= 90) {
            descriptionTV.setMaxLines(2);
        }

        // 2:00 long shows can display 4 lines of description
        else if (difference >= 120) {
            descriptionTV.setMaxLines(4);
        }

        descriptionTV.setEllipsize(TextUtils.TruncateAt.END);
        descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5));
        eventLL.addView(descriptionTV);
    }

    /* Add this view to the schedule UI */
    RelativeLayout rl = (RelativeLayout) rootView.findViewById(R.id.schedule_container_relativelayout);
    rl.addView(eventLL, rrLayoutParams);
}

From source file:com.androidhiddencamera.HiddenCameraFragment.java

/**
 * Add camera preview to the root of the activity layout.
 *
 * @return {@link CameraPreview} that was added to the view.
 */// w w w  .  j  a v  a2s.  c o  m
private CameraPreview addPreView() {
    //create fake camera view
    CameraPreview cameraSourceCameraPreview = new CameraPreview(getActivity(), this);
    cameraSourceCameraPreview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    View view = ((ViewGroup) getActivity().getWindow().getDecorView().getRootView()).getChildAt(0);

    if (view instanceof LinearLayout) {
        LinearLayout linearLayout = (LinearLayout) view;

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(1, 1);
        linearLayout.addView(cameraSourceCameraPreview, params);
    } else if (view instanceof RelativeLayout) {
        RelativeLayout relativeLayout = (RelativeLayout) view;

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(1, 1);
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
        relativeLayout.addView(cameraSourceCameraPreview, params);
    } else if (view instanceof FrameLayout) {
        FrameLayout frameLayout = (FrameLayout) view;

        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(1, 1);
        frameLayout.addView(cameraSourceCameraPreview, params);
    } else {
        throw new RuntimeException("Root view of the activity/fragment cannot be frame layout");
    }

    return cameraSourceCameraPreview;
}

From source file:com.androidhiddencamera.HiddenCameraActivity.java

/**
 * Add camera preview to the root of the activity layout.
 *
 * @return {@link CameraPreview} that was added to the view.
 *//*from   w ww . j a  v a  2 s.  com*/
private CameraPreview addPreView() {
    //create fake camera view
    CameraPreview cameraSourceCameraPreview = new CameraPreview(this, this);
    cameraSourceCameraPreview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    View view = ((ViewGroup) getWindow().getDecorView().getRootView()).getChildAt(0);

    if (view instanceof LinearLayout) {
        LinearLayout linearLayout = (LinearLayout) view;

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(1, 1);
        linearLayout.addView(cameraSourceCameraPreview, params);
    } else if (view instanceof RelativeLayout) {
        RelativeLayout relativeLayout = (RelativeLayout) view;

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(1, 1);
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
        relativeLayout.addView(cameraSourceCameraPreview, params);
    } else if (view instanceof FrameLayout) {
        FrameLayout frameLayout = (FrameLayout) view;

        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(1, 1);
        frameLayout.addView(cameraSourceCameraPreview, params);
    } else {
        throw new RuntimeException("Root view of the activity/fragment cannot be frame layout");
    }

    return cameraSourceCameraPreview;
}

From source file:org.orange.querysystem.ScoresActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case PASSWORD_PROMPT:
        final TextView textView = new TextView(this);
        textView.setText("?");
        textView.setTextSize(14);/*from www. ja v a2 s . co  m*/
        textView.setId(1);
        final EditText editText = new EditText(this);
        editText.setId(2);
        editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        editText.setEnabled(true);
        editText.setCursorVisible(true);
        editText.setLongClickable(true);
        editText.setFocusable(true);
        editText.setTransformationMethod(PasswordTransformationMethod.getInstance());

        RelativeLayout.LayoutParams tvlp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        RelativeLayout.LayoutParams etlp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        RelativeLayout relativeLayout = new RelativeLayout(this);
        tvlp.addRule(RelativeLayout.ALIGN_BASELINE, 2);
        etlp.addRule(RelativeLayout.RIGHT_OF, 1);
        relativeLayout.addView(textView, tvlp);
        relativeLayout.addView(editText, etlp);
        return new AlertDialog.Builder(this).setView(relativeLayout)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked OK so do some stuff */
                        if (editText.getText().toString()
                                .equals(SettingsActivity.getAccountPassword(ScoresActivity.this))) {
                            authenticated = true;
                            enterActivity();
                        } else {
                            editText.setText("");
                            Toast.makeText(ScoresActivity.this, "????",
                                    Toast.LENGTH_LONG).show();
                            finish();
                        }

                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked cancel so do some stuff */
                        finish();
                    }
                }).setOnKeyListener(new OnKeyListener() {
                    @Override
                    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                        if (keyCode == KeyEvent.KEYCODE_BACK) {
                            finish();
                            return true;
                        }
                        return false;
                    }
                }).create();

    default:
        return null;
    }
}

From source file:tv.acfun.video.HomeActivity.java

private void invalidateAvatarFrame() {
    mUser = null;/*w ww . jav a 2  s  . c  o  m*/
    RelativeLayout leftDrawer = (RelativeLayout) mDrawer.findViewById(R.id.left_drawer);
    leftDrawer.removeViewAt(0);
    mAvatarFrame = getLayoutInflater().inflate(R.layout.avatar, leftDrawer, false);
    leftDrawer.addView(mAvatarFrame, 0);
    mAvatar = (ImageView) mAvatarFrame.findViewById(android.R.id.icon);
    mNameText = (TextView) mAvatarFrame.findViewById(android.R.id.text1);
}