Android RelativeLayout - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:getPaddingBottom, getPaddingLeft, getPaddingRight, setPadding
 
    /** 
     * Sets the header padding back to original size. 
     */ 
    private void resetHeaderPadding() { 
        mRefreshView.setPadding(
                mRefreshView.getPaddingLeft(),
                mRefreshOriginalTopPadding,
                mRefreshView.getPaddingRight(),
                mRefreshView.getPaddingBottom());
    } 
 
    /** 
     * Resets the header to the original state. 
     */ 
    private void resetHeader() { 
        if (mRefreshState != TAP_TO_REFRESH) {
            mRefreshState = TAP_TO_REFRESH;
 
            resetHeaderPadding(); 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setLayoutParams, addView
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setLayoutParams, addView
  } 
 
  private View getWebView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    if ((row == null) || (row.findViewById(1337) == null)) {
      RelativeLayout layout = new RelativeLayout(activity);
      layout.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.FILL_PARENT, ListView.LayoutParams.WRAP_CONTENT));
      row = layout;
       
      WebView webView = new WebView(activity);
      webView.setId(1337);
      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
      float scale = activity.getResources().getDisplayMetrics().density;
      boolean leftPadding = (parent.getTag().equals("right"));
      params.setMargins((int)(20 * scale) * (leftPadding ? 2 : 1), (int)(0 * scale), (int)(20 * scale), 0);
      webView.setLayoutParams(params);
      layout.addView(webView);
    } 
       
    WebView webView = (WebView)row.findViewById(1337);

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setBackgroundColor
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		if (savedInstanceState != null)
			mColorRes = savedInstanceState.getInt("mColorRes");
		int color = getResources().getColor(mColorRes);
		// construct the RelativeLayout 
		RelativeLayout v = new RelativeLayout(getActivity());
		v.setBackgroundColor(color);		
		return v;
	} 
	 
	@Override 
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		outState.putInt("mColorRes", mColorRes);
	} 
	 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPadding, addView
public class ListItemFactory implements AbstractViewFactory 
{	 
	@Override 
	public Widget create(Activity activity, int handle)
	{ 
		RelativeLayout listItemLayout = new RelativeLayout( activity );
		listItemLayout.setPadding( 5, 5, 5, 5 );
		 
		TextView label = new TextView( activity );
		ImageView icon = new ImageView( activity );
		icon.setId( 100 );
		 
		RelativeLayout.LayoutParams labelParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT );
		labelParams.addRule( RelativeLayout.ALIGN_PARENT_RIGHT );
		labelParams.addRule( RelativeLayout.RIGHT_OF, icon.getId( ) );
		labelParams.addRule( RelativeLayout.CENTER_VERTICAL );
		labelParams.setMargins( 5, 0, 0, 5 );
		label.setLayoutParams( labelParams );
		 
		label.setTextSize( 15.0f );

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setId, setOnClickListener, setPadding, addView
		super(context, attrs, defStyle);
	} 
 
	@Override 
	protected View onCreateView(final ViewGroup parent) {		
		final RelativeLayout layout = new RelativeLayout(getContext());
		layout.setPadding(15, 5, 15, 5);
 
		 
		 
		//setup title 
		final RelativeLayout.LayoutParams titleparams = new RelativeLayout.LayoutParams(
				RelativeLayout.LayoutParams.WRAP_CONTENT,
				RelativeLayout.LayoutParams.WRAP_CONTENT);
		titleparams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		titleparams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
 
		final TextView title = new TextView(getContext());
		title.setText(getTitle());
		title.setTextSize(24);

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getPaddingBottom, getPaddingLeft, getPaddingRight, setPadding
			} 
		} 
	} 
 
	private void resetHeaderPadding() { 
		mRefreshView.setPadding(mRefreshView.getPaddingLeft(),
				mRefreshOriginalTopPadding, mRefreshView.getPaddingRight(),
				mRefreshView.getPaddingBottom());
	} 
 
	private void resetHeader() { 
		if (mRefreshState != TAP_TO_REFRESH) {
			mRefreshState = TAP_TO_REFRESH;
			resetHeaderPadding(); 
			mRefreshViewText.setText(R.string.pull_to_refresh_tap_label);
			mRefreshViewImage
					.setImageResource(R.drawable.ic_pulltorefresh_arrow);// 换成箭头
			mRefreshViewImage.clearAnimation();// 清除动画
			mRefreshViewImage.setVisibility(View.GONE);// 隐藏图标
			mRefreshViewProgress.setVisibility(View.GONE);// 隐藏进度条
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setLayoutParams, setMinimumHeight, setMinimumWidth, addView
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setBackgroundColor, setId, setLayoutParams, setPadding, addView
    setBackgroundColor(Color.WHITE);
    setLayoutParams(params);
  } 
 
  private void loadHeaderView(Context context) {
    headerView = new RelativeLayout(context);
    headerView.setId(HEADER_VIEW_ID);
     
    LayoutParams params = null;
    if (layoutHorizontally) {
      params = new LayoutParams((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float)250.0, getResources().getDisplayMetrics()), LayoutParams.MATCH_PARENT);
      params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, TRUE);
      headerView.setPadding(0, 0, 0, 0);
    } 
    else { 
      params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
      headerView.setPadding(0, 0, 0, (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float)20.0, getResources().getDisplayMetrics()));
    } 
    headerView.setLayoutParams(params);
    headerView.setBackgroundColor(Color.rgb(230, 236, 239));

7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android RelativeLayout Questions & Answers:

Other Android RelativeLayout Examples

37:		@Override
38:	    public boolean isViewFromObject(View view, Object object) {
39:	        return view == ((RelativeLayout) object);
40:	    }
41:		
-
73:		@Override
74:	    public void destroyItem(ViewGroup container, int position, Object object) {
75:	        ((ViewPager) container).removeView((RelativeLayout) object);
76:	 
77:	    }

Read More

See Code Examples for Android RelativeLayout Methods: