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) 

Source Link

Document

Adds a child view.

Usage

From source file:fr.shywim.antoinedaniel.utils.Utils.java

/**
 * First part of the click animation./*from   w  w w.j a va  2s.c o m*/
 *
 * @param context Any context.
 * @param v View who will have the effect.
 * @param isRoot Whether the passed view is the ViewGroup parent.
 */
public static void clickAnimDown(Context context, View v, boolean isRoot) {
    RelativeLayout root;
    if (isRoot)
        root = (RelativeLayout) v;
    else
        root = (RelativeLayout) v.getParent();
    final View rectView = new View(context);
    rectView.setId(R.id.rect_view_id);
    rectView.setVisibility(View.GONE);
    rectView.setBackgroundResource(R.drawable.square);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(v.getMeasuredWidth(),
            v.getMeasuredHeight());
    params.addRule(RelativeLayout.ALIGN_TOP, v.getId());
    rectView.setLayoutParams(params);
    AlphaAnimation rectAnim = new AlphaAnimation(0f, 0.4f);
    rectAnim.setFillAfter(true);
    rectAnim.setInterpolator(new AccelerateInterpolator());
    rectAnim.setDuration(150);
    rectAnim.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            rectView.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animation animation) {

        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
    root.addView(rectView);
    rectView.startAnimation(rectAnim);
}

From source file:com.kupay.decoder.DecoderActivity.java

public void startCamera() {

    //(SurfaceView) getView().findViewById(R.id.preview_view);
    RelativeLayout rl = (RelativeLayout) getView().findViewById(R.id.fitCamera);
    surfaceView = new SurfaceView(getActivity());
    SurfaceHolder surfaceHolder = surfaceView.getHolder();

    Log.v("app", "Cargando camara");
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    if (rl != null && surfaceView != null)
        rl.addView(surfaceView);

}

From source file:com.goldcard.igas.widget.tabindicator.TabPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;/*ww w .  ja  va2 s  .  c o  m*/
    tabView.setGravity(Gravity.CENTER);
    tabView.setFocusable(true);
    tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    if (iconResId != 0) {
        tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
    }
    RelativeLayout rr = new RelativeLayout(this.getContext());
    rr.setGravity(Gravity.CENTER);
    rr.setFocusable(true);
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    tabView.setLayoutParams(lp);
    rr.addView(tabView);
    mTabLayout.addView(rr, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}

From source file:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Show the alert//ww w . ja v a2s.com
 *
 * @param context                 application-specific resources
 * @param configuration           describes all device configuration information
 * @param text                    message to be displayed
 * @param forceClearPreviousAlert true will clear previous alert else keep it
 */
@SuppressLint("NewApi")
private static void showAlertOnScreen(final Activity context, final Configuration configuration,
        final String text, boolean forceClearPreviousAlert) {

    final ViewGroup mainView = ((ViewGroup) context.findViewById(android.R.id.content));
    boolean currentlyDisplayed = false;
    int viewId = R.id.alert_view_top;
    final TextView textView;
    boolean alertAlreadyExists = false;

    if (configuration.getOrientation().equals(Configuration.Orientation.BOTTOM)) {
        viewId = R.id.alert_view_bottom;
    }

    // Retrieving the view
    RelativeLayout relativeLayout = (RelativeLayout) mainView.findViewById(viewId);

    if (forceClearPreviousAlert) {
        mainView.removeView(relativeLayout);
        relativeLayout = null;
    }

    // Creating the view
    if (relativeLayout == null) {

        // Main layout
        relativeLayout = new RelativeLayout(context);
        relativeLayout.setId(viewId);
        relativeLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, configuration.getHeight()));
        relativeLayout.setGravity(Gravity.CENTER);

        // Textview
        textView = new TextView(context);
        textView.setId(R.id.alert_view_text);
        textView.setGravity(Gravity.CENTER);
        textView.setLayoutParams(
                new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        relativeLayout.addView(textView);

        setIcon(context, configuration, relativeLayout, textView);

        if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
            relativeLayout.setY(-configuration.getHeight());
        } else {
            relativeLayout.setY(mainView.getHeight());
        }

        // Adding the view to the global layout
        mainView.addView(relativeLayout, 0);
        relativeLayout.bringToFront();
        relativeLayout.requestLayout();
        relativeLayout.invalidate();
    }
    // View already exists
    else {
        alertAlreadyExists = true;
        textView = (TextView) relativeLayout.findViewById(R.id.alert_view_text);

        if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
            if (relativeLayout.getY() == 0) {
                currentlyDisplayed = true;
            }
        } else {
            if (relativeLayout.getY() < mainView.getHeight()) {
                currentlyDisplayed = true;
            }
        }

        // The view is currently shown to the user
        if (currentlyDisplayed) {

            // If the message is not the same, we hide the current message and display the new one
            if (!StringUtils.equals(text, textView.getText())) {
                // Anim out the current message
                ViewPropertyAnimator viewPropertyAnimator = animOut(configuration, mainView, relativeLayout);

                final RelativeLayout relativeLayoutFinal = relativeLayout;

                if (viewPropertyAnimator != null) {
                    // Anim in the new message after the animation out has finished
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                        viewPropertyAnimator.setListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator animation) {
                                setIcon(context, configuration, relativeLayoutFinal, textView);
                                animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                            }
                        });
                    } else {
                        viewPropertyAnimator.withEndAction(new Runnable() {
                            @Override
                            public void run() {
                                setIcon(context, configuration, relativeLayoutFinal, textView);
                                animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                            }
                        });
                    }
                } else {
                    setIcon(context, configuration, relativeLayoutFinal, textView);
                    animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                }
            }
        }
    }

    final RelativeLayout relativeLayoutFinal = relativeLayout;

    // Close the alert by clicking the layout
    if (configuration.isCloseable()) {
        relativeLayout.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                animOut(configuration, mainView, relativeLayoutFinal);
                v.performClick();
                return true;
            }
        });
    }

    if (!currentlyDisplayed) {
        // Set the icon in case the alert already exists but it's not currently displayed
        if (alertAlreadyExists) {
            setIcon(context, configuration, relativeLayoutFinal, textView);
        }

        // We anim in the alert
        animIn(configuration, relativeLayoutFinal, textView, mainView, text);
    }
}

From source file:com.zt.hackman.model.HackmanModel.java

/**
 * ?/*from   w  ww .j av  a  2 s  .  c om*/
 */
public void changeImage(ImageItem item, int current, RelativeLayout btn) {

    btn.removeAllViews();
    ImageView imageView = new ImageView(ac);
    imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    btn.addView(imageView);
    ImageLoader.getInstance().displayImage("file://" + item.path, imageView, BaseApp.options);
    switch (current) {
    case 1:
        response.idenFrontImage = new File(item.path);
        break;
    case 2:
        response.idenReserveImage = new File(item.path);
        break;
    case 3:
        response.driveImage = new File(item.path);
        break;
    case 4:
        response.driveImage2 = new File(item.path);
        break;
    case 5:
        response.doBusinessImage = new File(item.path);
        break;
    case 6:
        response.vehicleImg = new File(item.path);
        break;
    case 7:
        response.vehicleLicenseImg = new File(item.path);
        break;
    case 8:
        response.vehicleLicenseImg2 = new File(item.path);
        break;
    case 9:
        response.operationLicenseImg = new File(item.path);
        break;

    }

}

From source file:at.alladin.rmbt.android.map.RMBTMapFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final RelativeLayout view = (RelativeLayout) inflater.inflate(R.layout.map_google, container, false);
    registerListeners(view);//from  w ww .j ava 2s  .  co m

    final int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
    if (errorCode != ConnectionResult.SUCCESS) {
        final Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(errorCode, getActivity(), 0);
        errorDialog.show();
        getFragmentManager().popBackStack();
        return view;
    }

    View mapView = super.onCreateView(inflater, container, savedInstanceState);

    final RelativeLayout mapViewContainer = (RelativeLayout) view.findViewById(R.id.mapViewContainer);
    mapViewContainer.addView(mapView);

    ProgressBar progessBar = new ProgressBar(getActivity());
    final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, 1);
    progessBar.setLayoutParams(layoutParams);
    progessBar.setVisibility(View.GONE);
    view.addView(progessBar);

    return view;
}

From source file:com.qs.qswlw.view.Mypager.UltraViewPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    int realPosition = position;
    //TODO/*w w w . j a v  a 2 s. c o  m*/
    if (enableLoop && adapter.getCount() != 0) {
        realPosition = position % adapter.getCount();
    }

    Object item = adapter.instantiateItem(container, realPosition);
    //TODO
    View childView = null;
    if (item instanceof View)
        childView = (View) item;
    //        if (item instanceof RecyclerView.ViewHolder)
    //            childView = ((RecyclerView.ViewHolder) item).itemView;

    ViewPager viewPager = (ViewPager) container;
    int childCount = viewPager.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = viewPager.getChildAt(i);
        if (isViewFromObject(child, item)) {
            viewArray.put(realPosition, child);
            break;
        }
    }

    if (isEnableMultiScr()) {
        if (scrWidth == 0) {
            scrWidth = container.getResources().getDisplayMetrics().widthPixels;
        }
        RelativeLayout relativeLayout = new RelativeLayout(container.getContext());

        if (childView.getLayoutParams() != null) {
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                    (int) (scrWidth * multiScrRatio), ViewGroup.LayoutParams.MATCH_PARENT);

            layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
            childView.setLayoutParams(layoutParams);
        }

        container.removeView(childView);
        relativeLayout.addView(childView);

        container.addView(relativeLayout);
        return relativeLayout;
    }

    return item;
}

From source file:com.tmall.ultraviewpager.UltraViewPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    int realPosition = position;
    //TODO/*w w  w.j  ava  2s .c  o m*/
    if (enableLoop && adapter.getCount() != 0) {
        realPosition = position % adapter.getCount();
    }

    Object item = adapter.instantiateItem(container, realPosition);
    //TODO
    View childView = null;
    if (item instanceof View)
        childView = (View) item;
    if (item instanceof RecyclerView.ViewHolder)
        childView = ((RecyclerView.ViewHolder) item).itemView;

    ViewPager viewPager = (ViewPager) container;
    int childCount = viewPager.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = viewPager.getChildAt(i);
        if (isViewFromObject(child, item)) {
            viewArray.put(realPosition, child);
            break;
        }
    }

    if (isEnableMultiScr()) {
        if (scrWidth == 0) {
            scrWidth = container.getResources().getDisplayMetrics().widthPixels;
        }
        RelativeLayout relativeLayout = new RelativeLayout(container.getContext());

        if (childView.getLayoutParams() != null) {
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                    (int) (scrWidth * multiScrRatio), ViewGroup.LayoutParams.MATCH_PARENT);

            layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
            childView.setLayoutParams(layoutParams);
        }

        container.removeView(childView);
        relativeLayout.addView(childView);

        container.addView(relativeLayout);
        return relativeLayout;
    }

    return item;
}

From source file:com.support.android.designlibdemo.PetsDetailActivity.java

/**********************************************************************************************/

private AlertDialog createReportDialog(String titulo, String message) {
    // Instanciamos un nuevo AlertDialog Builder y le asociamos titulo y mensaje
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle(titulo);
    alertDialogBuilder.setMessage(message);
    RelativeLayout linearLayout = new RelativeLayout(this);
    final EditText link = new EditText(this);
    link.setHint("Causa de la denuncia");
    link.setWidth(750);//from   w  ww  .  ja v  a2  s .c  o m
    linearLayout.addView(link);
    linearLayout.setPadding(70, 0, 0, 0);
    alertDialogBuilder.setView(linearLayout);
    link.invalidate();
    linearLayout.invalidate();
    final String petId = getIntent().getStringExtra("id");

    // Creamos un nuevo OnClickListener para el boton OK que realice la conexion
    DialogInterface.OnClickListener listenerOk = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            reportComplain(petId, loginUser.getId(), link.getText().toString());
        }
    };

    // Creamos un nuevo OnClickListener para el boton Cancelar
    DialogInterface.OnClickListener listenerCancelar = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    };

    // Asignamos los botones positivo y negativo a sus respectivos listeners
    //OJO: estan al reves para que sea display si - no en vez de no - si
    alertDialogBuilder.setPositiveButton(R.string.dialogCancel, listenerCancelar);
    alertDialogBuilder.setNegativeButton(R.string.dialogSend, listenerOk);

    return alertDialogBuilder.create();
}

From source file:com.support.android.designlibdemo.PetsDetailActivity.java

/**********************************************************************************************/

private AlertDialog createPublicationDialog(String titulo, String message) {
    // Instanciamos un nuevo AlertDialog Builder y le asociamos titulo y mensaje
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle(titulo);
    alertDialogBuilder.setMessage(message);
    RelativeLayout linearLayout = new RelativeLayout(this);
    final EditText link = new EditText(this);
    link.setText(buildDescription());/*from  w ww . jav  a2  s.  c  o  m*/
    link.setTextSize(12);
    link.setWidth(750);
    linearLayout.addView(link);
    linearLayout.setPadding(70, 0, 0, 0);
    alertDialogBuilder.setView(linearLayout);
    link.invalidate();
    linearLayout.invalidate();
    //        final String petId = getIntent().getStringExtra("id");

    // Creamos un nuevo OnClickListener para el boton OK que realice la conexion
    DialogInterface.OnClickListener listenerOk = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String texto = link.getText().toString();
            shareOnFacebook(texto);
            Toast.makeText(getApplicationContext(), "Publicacin compartida correctamente", Toast.LENGTH_SHORT)
                    .show();
        }
    };

    // Creamos un nuevo OnClickListener para el boton Cancelar
    DialogInterface.OnClickListener listenerCancelar = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    };

    // Asignamos los botones positivo y negativo a sus respectivos listeners
    //OJO: estan al reves para que sea display si - no en vez de no - si
    alertDialogBuilder.setPositiveButton(R.string.dialogCancel, listenerCancelar);
    alertDialogBuilder.setNegativeButton(R.string.dialogPublish, listenerOk);

    return alertDialogBuilder.create();
}