Example usage for android.widget RelativeLayout setGravity

List of usage examples for android.widget RelativeLayout setGravity

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setGravity(int gravity) 

Source Link

Document

Describes how the child views are positioned.

Usage

From source file:me.ziccard.secureit.fragment.EmptyFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if ((savedInstanceState != null) && savedInstanceState.containsKey(CONTENT)) {
        mContent = savedInstanceState.getString(CONTENT);
    }//from ww w. j a va 2 s .  co m

    TextView text = new TextView(getActivity());
    text.setGravity(Gravity.CENTER);
    text.setText(mContent);
    text.setTextSize(20 * getResources().getDisplayMetrics().density);

    RelativeLayout layout = new RelativeLayout(getActivity());
    layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    layout.setGravity(Gravity.CENTER);

    RelativeLayout alert = new RelativeLayout(getActivity());
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    params.leftMargin = 20;
    params.rightMargin = 20;
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    alert.setLayoutParams(params);
    alert.setBackgroundResource(R.drawable.red_back);
    alert.setPadding(30, 0, 30, 0);
    alert.addView(text);
    layout.addView(alert);

    return layout;
}

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;//from  w  w  w. ja  v a2  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//from w  ww . j a va  2  s  . c om
 *
 * @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:net.wequick.small.webkit.WebActivity.java

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

    int theme = Small.getWebActivityTheme();
    if (theme != 0)
        setTheme(theme);//from  w w  w.  j  a  v  a 2 s. c  om

    boolean fullscreen = false;
    CharSequence queryTitle;
    Uri uri = Small.getUri(this);
    if (uri != null) {
        String param = uri.getQueryParameter("_fullscreen");
        if (param != null) {
            fullscreen = param.equals("1");
        }
        queryTitle = uri.getQueryParameter("_title");
        if (queryTitle != null) {
            super.setTitle(queryTitle);
            mCanSetTitle = false;
        }
    }

    // Init actionBar
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        if (fullscreen) {
            actionBar.hide();
        } else {
            actionBar.show();
            Activity parent = getParent();
            if (parent == null) { // If is created by a LocalActivityManager, parent is not null
                actionBar.setDisplayHomeAsUpEnabled(true);
            }
        }
    }
    mFullscreen = fullscreen;

    // Initialize content wrapper
    RelativeLayout wrapper = new RelativeLayout(this);
    wrapper.setGravity(Gravity.CENTER);
    setContentView(wrapper);

    // Initialize webView
    mWebView = new WebView(this);
    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    wrapper.addView(mWebView, 0, layoutParams);

    // Try to load title from cache
    mUrl = getIntent().getStringExtra("url");
    if (mCanSetTitle) {
        CharSequence title = getCacheTitle(mUrl);
        if (title != null) {
            super.setTitle(title);
        }
    }
}

From source file:com.example.damerap_ver1.IntroVideoActivity.java

/**
* Create the view in which the video will be rendered.
*//*w  w  w. j a va  2s . c o  m*/
private void setupView() {
    LinearLayout lLinLayout = new LinearLayout(this);
    lLinLayout.setId(1);
    lLinLayout.setOrientation(LinearLayout.VERTICAL);
    lLinLayout.setGravity(Gravity.CENTER);
    lLinLayout.setBackgroundColor(Color.BLACK);

    LayoutParams lLinLayoutParms = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);
    lLinLayout.setLayoutParams(lLinLayoutParms);

    this.setContentView(lLinLayout);

    RelativeLayout lRelLayout = new RelativeLayout(this);
    lRelLayout.setId(2);
    lRelLayout.setGravity(Gravity.CENTER);
    lRelLayout.setBackgroundColor(Color.BLACK);
    android.widget.RelativeLayout.LayoutParams lRelLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
    lRelLayout.setLayoutParams(lRelLayoutParms);
    lLinLayout.addView(lRelLayout);

    mVideoView = new VideoView(this);
    mVideoView.setId(3);
    android.widget.RelativeLayout.LayoutParams lVidViewLayoutParams = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lVidViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    mVideoView.setLayoutParams(lVidViewLayoutParams);
    lRelLayout.addView(mVideoView);

    mProgressBar = new ProgressBar(this);
    mProgressBar.setId(4);
    android.widget.RelativeLayout.LayoutParams lProgressBarLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lProgressBarLayoutParms.addRule(RelativeLayout.CENTER_IN_PARENT);
    mProgressBar.setLayoutParams(lProgressBarLayoutParms);
    lRelLayout.addView(mProgressBar);

    mProgressMessage = new TextView(this);
    mProgressMessage.setId(5);
    android.widget.RelativeLayout.LayoutParams lProgressMsgLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lProgressMsgLayoutParms.addRule(RelativeLayout.CENTER_HORIZONTAL);
    lProgressMsgLayoutParms.addRule(RelativeLayout.BELOW, 4);
    mProgressMessage.setLayoutParams(lProgressMsgLayoutParms);
    mProgressMessage.setTextColor(Color.LTGRAY);
    mProgressMessage.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8);
    mProgressMessage.setText("...");
    lRelLayout.addView(mProgressMessage);
}

From source file:com.game.simple.Game3.java

private void createAd() {

    adView = new AdView(this);
    adView.setAdUnitId(AD_UNIT_ID);//from  w  ww  .j  a v a  2s.com
    adView.setAdSize(AdSize.BANNER);
    try {
        AdView.LayoutParams layoutParams = new AdView.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);

        RelativeLayout relativeLayout = new RelativeLayout(this);

        RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT);

        relativeLayout.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);

        adView.setLayoutParams(layoutParams);

        relativeLayout.addView(adView);

        addContentView(relativeLayout, rlp);

        AdRequest req = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .addTestDevice("6BAC439445EBA320C6E42298650F159E").build();

        adView.loadAd(req);

        adView.setVisibility(View.INVISIBLE);

    } catch (Exception e) {
        // TODO: handle exception
    }
}

From source file:cn.mailchat.view.PagerSlidingTabStrip.java

private void addIconTab(final int position, int resId) {

    //layout/*  w w w.  ja  va 2  s .co m*/
    RelativeLayout tabLayout = new RelativeLayout(getContext());
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    tabLayout.setLayoutParams(layoutParams);
    tabLayout.setGravity(Gravity.CENTER);

    //tab
    RelativeLayout.LayoutParams imgParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    imgParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    ImageButton tab = new ImageButton(getContext());
    tab.setId(100 + position);
    tab.setImageResource(resId);
    tabLayout.addView(tab, imgParams);

    //???
    RelativeLayout.LayoutParams viewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    viewParams.addRule(RelativeLayout.RIGHT_OF, tab.getId());
    View view = new View(getContext());
    ViewGroup.LayoutParams vParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    view.setLayoutParams(vParams);
    tabLayout.addView(view, viewParams);

    addTab(position, tabLayout);

    /*BadgeView badgeView = new BadgeView(getContext(), view);
      badgeView.setText("");
      badgeView.setTextSize(10);
      badgeView.setGravity(Gravity.CENTER);
      badgeView.setBackgroundResource(R.drawable.main_tab_new_message_notify);
      badgeView.setBadgePosition(BadgeView.POSITION_VERTICAL_LEFT);
      badgeView.show();*/
}

From source file:com.wit.and.dialog.ListDialog.java

/**
 *//*w  w  w . j  av a 2s .  com*/
@Override
protected View onCreateBodyView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = inflater.getContext();

    // There will be default empty view behind the list view in relative layout.
    RelativeLayout layout = new RelativeLayout(context);
    if (container instanceof LinearLayout) {
        // Apply valid linear layout params to fit with list view just left space in the dialog main view.
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, 0);
        layoutParams.weight = 1;
        layout.setLayoutParams(layoutParams);
    } else {
        // Apply neutral layout params.
        layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
    }
    layout.setGravity(Gravity.CENTER);
    // Do not allow to apply style to body view.
    // layout.setId(R.id.Dialog_Layout_Body);

    // Create empty view and insert it into body layout behind the list view.
    View emptyView = onCreateEmptyView(inflater, container, savedInstanceState);
    if (emptyView != null) {
        layout.addView(emptyView);
    }

    // Create list view and insert it into body layout.
    ListView listView = onCreateListView(inflater, layout, savedInstanceState);
    if (listView != null) {
        layout.addView(listView);
    }
    return layout;
}

From source file:com.near.chimerarevo.fragments.PostFragment.java

private void addYoutubeVideo(String url) {
    final String yturl;
    if (url.contains("embed")) {
        String temp = url.split("embed/")[1];
        if (url.contains("feature")) {
            temp = temp.split("feature=")[0];
            yturl = temp.substring(0, temp.length() - 1);
        } else/*from  ww w .  j a va  2  s.  com*/
            yturl = temp;
    } else if (url.contains("youtu.be")) {
        yturl = url.split("youtu.be/")[1];
    } else
        return;

    final RelativeLayout rl = new RelativeLayout(getActivity());
    YouTubeThumbnailView yt = new YouTubeThumbnailView(getActivity());
    ImageView icon = new ImageView(getActivity());

    try {
        yt.setTag(yturl);
        yt.initialize(Constants.YOUTUBE_API_TOKEN, new OnInitializedListener() {
            @Override
            public void onInitializationFailure(YouTubeThumbnailView thumbView,
                    YouTubeInitializationResult error) {
                rl.setVisibility(View.GONE);
            }

            @Override
            public void onInitializationSuccess(YouTubeThumbnailView thumbView,
                    YouTubeThumbnailLoader thumbLoader) {
                thumbLoader.setVideo(yturl);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }

    RelativeLayout.LayoutParams obj_params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    obj_params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    obj_params.addRule(RelativeLayout.CENTER_VERTICAL);
    yt.setLayoutParams(obj_params);

    icon.setImageResource(R.drawable.yt_play_button);
    icon.setLayoutParams(obj_params);

    RelativeLayout.LayoutParams rl_params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    rl_params.setMargins(0, 10, 0, 0);
    rl.setLayoutParams(rl_params);
    rl.setGravity(Gravity.CENTER_HORIZONTAL);
    rl.setClickable(true);

    rl.addView(yt);
    rl.addView(icon);

    rl.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(getActivity(), YoutubeActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            i.putExtra(Constants.KEY_VIDEO_URL, yturl);
            startActivity(i);
        }
    });

    lay.addView(rl);
}