RelativeLayout setGravity - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for RelativeLayout setGravity method.

This code example shows how to use the following methods:addView, setGravity
		 
		super.onCreate ( savedInstanceState );
 
		sMovie = this;
		 
		RelativeLayout layout = new RelativeLayout ( this );
		layout.setGravity ( Gravity.CENTER );
		 
		mVideoView = new VideoView ( this );
		mVideoView.setOnPreparedListener ( this );
        mVideoView.setOnCompletionListener ( this );
 
		layout.addView ( mVideoView, new RelativeLayout.LayoutParams ( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT ));
		setContentView ( layout );		
		 
		String url = this.getIntent ().getStringExtra ( "url" );
		 
		MoaiLog.i ( "MoaiMoviePlayer onCreate: Initializing video player with media URL " + url );
 
		mVideoView.setVideoURI ( Uri.parse ( url ));
8
CodeRank
This code example shows how to use the following methods:setLayoutParams, addView, setGravity
 
		layout = new LinearLayout(this);
		layout.setLayoutParams(fillParams);
		layout.setOrientation(LinearLayout.VERTICAL);
 
		RelativeLayout cannelLayout = new RelativeLayout(this);
		cannelLayout.setLayoutParams(fillWrapParams);
		// cannelLayout.setBackgroundDrawable(BackGroudSeletor.getdrawble("up_bg2x", 
		// getApplication())); 
		cannelLayout.setGravity(LinearLayout.HORIZONTAL);
 
		Button returnBtn = new Button(this);
		String[] pngArray = { "quxiao_btn2x", "quxiao_btn_hover" };
		// returnBtn.setBackgroundDrawable(BackGroudSeletor.createBgByImageIds(pngArray, 
		// getApplication())); 
		returnBtn.setText("取消");
		wrapParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
		wrapParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
		wrapParams.leftMargin = 10;
		wrapParams.topMargin = 10;

6
CodeRank
This code example shows how to use the following methods:setLayoutParams, setVisibility, setWillNotDraw, addView, setGravity
6
CodeRank
This code example shows how to use the following methods:addView, setGravity
This code example shows how to use the following methods:setBackgroundColor, setId, setLayoutParams, addView, setGravity
5
CodeRank
This code example shows how to use the following methods:setLayoutParams, addView, setGravity
This code example shows how to use the following methods:addView, setGravity
        activity.setContentView(lLayout);
    } 
     
    public void dynamicRelativeLayout(Activity activity) {
        // µÚÒ»ÊÇÈÝÆ÷£¬´´½¨Ò»¸öÈÝÆ÷(ÕâÀïÓÃLinearLayout¾ÙÀý)£» 
        RelativeLayout rLayout = new RelativeLayout(activity);// (ÕâÀïµÄthisÊÇÒ»¸öContext±äÁ¿)£»
        // µÚ¶þÊÇÈÝÆ÷µÄϸ½Ú£¬Ò²¾ÍÊÇÊôÐÔ²¿·Ö£»±ÈÈ磬ÈÝÆ÷ÀïµÄ¿Ø¼þÊÇÔõÑùÅŵģ» 
        rLayout.setGravity(Gravity.CENTER);
         
        // µÚÈýÊÇÈÝÆ÷ÀïµÄ¿Ø¼þ£¬´´½¨×Ô¼ºÏëÒªµÄ¿Ø¼þ£» 
        EditText editText = new EditText(activity);
        Button button = new Button(activity);// ÕâÀïµÄthis¶¼ÊÇÒ»¸öContext±äÁ¿£»
        editText.setLines(3);
        editText.setGravity(Gravity.TOP | Gravity.LEFT);
        button.setText("²åÈëËæ»ú±íÇé");
         
        // µÚËÄÊÇÈÝÆ÷µÄϸ½Ú£¬¾ÍÊÇÉèÖÃÈÝÆ÷µÄÊôÐÔ£» 
        RelativeLayout.LayoutParams rParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        // ÉèÖÃRelativeLayout¿Ø¼þÏÂandroid:layout_centerHorizontalÊôÐÔ 
        rParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

5
CodeRank
This code example shows how to use the following methods:getLayoutParams, requestLayout, setGravity
 
	private void expandItem(int position) {
		final int first = getFirstVisiblePosition();
		RelativeLayout v = (RelativeLayout) getChildAt(position - first);
		if (v != null && mFloatView != null) {
			ViewGroup.LayoutParams lp = v.getLayoutParams();
			int oldHeight = lp.height;
			if (lp.height == mItemHeightCollapsed && position == mSrcDragPos) {
				lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
			} else if (lp.height == ViewGroup.LayoutParams.WRAP_CONTENT
					&& position != mExpDragPos) {
				lp.height = v.getHeight() + mFloatViewHeight;
				if (position > mSrcDragPos)
					v.setGravity(Gravity.TOP);
				else 
					v.setGravity(Gravity.BOTTOM);
			} 
			if (lp.height != oldHeight)
				v.requestLayout();
		} 

4
CodeRank

Related RelativeLayout setGravity Questions & Answers:

setGravity Method Overview
Describes how the child views are positioned.
See Code Examples for other Android RelativeLayout Methods: