Java Code Examples for android.widget.RelativeLayout.setGravity()

The following are Jave code examples for showing how to use setGravity() of the android.widget.RelativeLayout class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: letv   File: ChannelTabPageIndicator.java   Source Code and License Vote up 6 votes
protected void addTab(int index, CharSequence text, int iconResId) {
    TabView tabView = new TabView(this, getContext(), text);
    tabView.setIndex(index);
    tabView.setFocusable(true);
    tabView.setOnClickListener(this.mTabClickListener);
    if (iconResId != 0) {
        tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
    }
    int width = this.mMeanWidth == -1 ? getTabWidth(text) : this.mMeanWidth;
    if (this.mMeanWidth != -1) {
        tabView.setSize(this.mMeanWidth, UIsUtils.dipToPx(38.0f));
    } else {
        tabView.setSize(width, UIsUtils.dipToPx(38.0f));
    }
    RelativeLayout relativeLayout = new RelativeLayout(this.mContext);
    relativeLayout.setGravity(17);
    relativeLayout.setLayoutParams(new LayoutParams(-2, UIsUtils.dipToPx(38.0f)));
    LayoutParams params = new LayoutParams(-2, UIsUtils.dipToPx(38.0f));
    params.setMargins(TAB_MARGIN, 0, TAB_MARGIN, 0);
    tabView.setLayoutParams(params);
    relativeLayout.addView(tabView);
    if (this.mIsHome) {
        ThemeDataManager.getInstance(this.mContext).setContentTheme(tabView, ThemeDataManager.NAME_TOP_NAVIGATION_COLOR);
    }
    ImageView imageView = new ImageView(this.mContext);
    LayoutParams imageViewParams = new LayoutParams(width, UIsUtils.dipToPx(2.0f));
    imageViewParams.setMargins(TAB_MARGIN, UIsUtils.dipToPx(36.0f), TAB_MARGIN, 0);
    imageView.setLayoutParams(imageViewParams);
    relativeLayout.addView(imageView);
    imageView.setBackgroundDrawable(getResources().getDrawable(2130838177));
    if (this.mIsHome) {
        ThemeDataManager.getInstance(this.mContext).setShapeSelectorViewTheme(imageView, ThemeDataManager.NAME_TOP_NAVIGATION_COLOR, 2, true);
    }
    this.mTabLayout.addView(relativeLayout);
}
 
Example 2
Project: Flashcard-Maker-Android   File: RVCardsAdapter.java   Source Code and License Vote up 6 votes
public ViewHolder(View itemView) {
    super(itemView);
    frontText = (AutoResizeTextView) itemView.findViewById(R.id.textFront);
    frontText.setOnClickListener(this);
    backText = (AutoResizeTextView) itemView.findViewById(R.id.textBack);
    backText.setOnClickListener(this);
    delete = (ImageView) itemView.findViewById(R.id.delete);
    delete.setOnClickListener(this);
    flip = (ImageView) itemView.findViewById(R.id.flip);
    flip.setOnClickListener(this);
    flipBack = (ImageView) itemView.findViewById(R.id.flipBack);
    flipBack.setOnClickListener(this);
    front = (RelativeLayout) itemView.findViewById(R.id.front);
    back = (RelativeLayout) itemView.findViewById(R.id.back);
    back.setGravity(View.GONE);
    bg = (ImageView) itemView.findViewById(R.id.card);
    bgBack = (ImageView) itemView.findViewById(R.id.cardBack);
    editCard = (ImageView) itemView.findViewById(R.id.editCard);
    editCard.setOnClickListener(this);
    editCardBack = (ImageView) itemView.findViewById(R.id.editCardBack);
    editCardBack.setOnClickListener(this);
}
 
Example 3
Project: StickyHeaderListView   File: StickyHeaderListView.java   Source Code and License Vote up 6 votes
private void init(Context context, AttributeSet attrs) {
    mListView = new InternalListView(getContext(), attrs);
    LayoutParams listParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    listParams.addRule(ALIGN_PARENT_TOP);
    mListView.setLayoutParams(listParams);
    mListView.setOnScrollListener(new HeaderListViewOnScrollListener());
    mListView.setVerticalScrollBarEnabled(true);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (mAdapter != null) {
                mAdapter.onItemClick(parent, view, position, id);
            }
        }
    });
    addView(mListView);

    mHeader = new RelativeLayout(getContext());
    LayoutParams headerParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    headerParams.addRule(ALIGN_PARENT_TOP);
    mHeader.setLayoutParams(headerParams);
    mHeader.setGravity(Gravity.BOTTOM);
    addView(mHeader);
}
 
Example 4
Project: SgPSI   File: DialogFactory.java   Source Code and License Vote up 5 votes
public static ProgressBar DProgressBar(Context context) {

        ViewGroup layout = (ViewGroup) ((Activity) context).findViewById(android.R.id.content).getRootView();
        ProgressBar mProgressBar = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
        mProgressBar.setIndeterminate(true);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        RelativeLayout rl = new RelativeLayout(context);
        rl.setGravity(Gravity.CENTER);
        rl.addView(mProgressBar);
        layout.addView(rl, params);
        return mProgressBar;
    }
 
Example 5
Project: boohee_v5.6   File: BarcodeScannerView.java   Source Code and License Vote up 5 votes
public final void setupLayout() {
    this.mPreview = new CameraPreview(getContext());
    RelativeLayout relativeLayout = new RelativeLayout(getContext());
    relativeLayout.setGravity(17);
    relativeLayout.setBackgroundColor(-16777216);
    relativeLayout.addView(this.mPreview);
    addView(relativeLayout);
    this.mViewFinderView = createViewFinderView(getContext());
    if (this.mViewFinderView instanceof View) {
        addView((View) this.mViewFinderView);
        return;
    }
    throw new IllegalArgumentException("IViewFinder object returned by 'createViewFinderView()' should be instance of android.view.View");
}
 
Example 6
Project: phonk   File: AppRunnerService.java   Source Code and License Vote up 5 votes
public RelativeLayout initLayout() {
    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    // set the parent
    parentScriptedLayout = new RelativeLayout(this);
    parentScriptedLayout.setLayoutParams(layoutParams);
    parentScriptedLayout.setGravity(Gravity.BOTTOM);
    parentScriptedLayout.setBackgroundColor(getResources().getColor(R.color.transparent));

    return parentScriptedLayout;
}
 
Example 7
Project: GitHub   File: ContactsListviewItemLayout.java   Source Code and License Vote up 4 votes
public static RelativeLayout create(Context context) {
	SizeHelper.prepare(context);

	RelativeLayout root = new RelativeLayout(context);
	root.setId(ResHelper.getIdRes(context, "rl_lv_item_bg"));
	AbsListView.LayoutParams params = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
			SizeHelper.fromPxWidth(95));
	root.setLayoutParams(params);
	int padding = SizeHelper.fromPxWidth(14);
	root.setPadding(padding, padding, padding, padding);
	root.setGravity(Gravity.CENTER_VERTICAL);
	root.setBackgroundColor(0xffffffff);

	AsyncImageView contactImage = new AsyncImageView(context);
	contactImage.setId(ResHelper.getIdRes(context, "iv_contact"));
	RelativeLayout.LayoutParams contactImageParams = new RelativeLayout.LayoutParams(SizeHelper.fromPxWidth(64),
			SizeHelper.fromPxWidth(64));
	contactImageParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
	contactImage.setLayoutParams(contactImageParams);
	contactImage.setScaleType(ScaleType.FIT_CENTER);
	root.addView(contactImage);

	LinearLayout wrapper = new LinearLayout(context);
	RelativeLayout.LayoutParams wrapperParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
			RelativeLayout.LayoutParams.WRAP_CONTENT);
	wrapperParams.addRule(RelativeLayout.RIGHT_OF, ResHelper.getIdRes(context, "iv_contact"));
	wrapperParams.addRule(RelativeLayout.CENTER_VERTICAL);
	wrapperParams.leftMargin = SizeHelper.fromPxWidth(12);
	wrapper.setLayoutParams(wrapperParams);
	wrapper.setOrientation(LinearLayout.VERTICAL);
	root.addView(wrapper);

	TextView name = new TextView(context);
	name.setId(ResHelper.getIdRes(context, "tv_name"));
	LinearLayout.LayoutParams nameParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	name.setLayoutParams(nameParams);
	name.setTextColor(0xff333333);
	name.setTextSize(TypedValue.COMPLEX_UNIT_PX,SizeHelper.fromPxWidth(28));
	wrapper.addView(name);

	TextView contact = new TextView(context);
	contact.setId(ResHelper.getIdRes(context, "tv_contact"));
	LinearLayout.LayoutParams contactParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	contact.setLayoutParams(contactParams);
	contact.setTextColor(0xff999999);
	contact.setTextSize(TypedValue.COMPLEX_UNIT_PX,SizeHelper.fromPxWidth(22));
	wrapper.addView(contact);

	Button add = new Button(context);
	add.setId(ResHelper.getIdRes(context, "btn_add"));
	RelativeLayout.LayoutParams addParams = new RelativeLayout.LayoutParams(SizeHelper.fromPxWidth(92),
			SizeHelper.fromPxWidth(46));
	addParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
	addParams.addRule(RelativeLayout.CENTER_VERTICAL);
	add.setLayoutParams(addParams);
	int resid = ResHelper.getStringRes(context, "smssdk_add_contact");
	add.setText(resid);
	add.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(22));
	add.setTextColor(0xff797979);
	//resid = R.getBitmapRes(context, "smssdk_corners_bg");
	add.setBackgroundDrawable(DrawableHelper.createCornerBg(context));
	add.setPadding(0, 0, 0, 0);
	root.addView(add);

	return root;
}
 
Example 8
Project: AndroidAppBoilerplate   File: ProgressBarHandler.java   Source Code and License Vote up 4 votes
public ProgressBarHandler(Context context) {

        ViewGroup layout = (ViewGroup) ((Activity) context).findViewById(android.R.id.content).getRootView();

        mProgressBar = new ProgressBar(context, null);
        mProgressBar.setIndeterminate(true);

        mProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary),
                android.graphics.PorterDuff.Mode.MULTIPLY);

        RelativeLayout.LayoutParams params = new
                RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);

        RelativeLayout rl = new RelativeLayout(context);

        rl.setGravity(Gravity.CENTER);
        rl.addView(mProgressBar);

        layout.addView(rl, params);

        hideProgress();
    }
 
Example 9
Project: Leanplum-Android-SDK   File: BaseMessageDialog.java   Source Code and License Vote up 4 votes
protected BaseMessageDialog(Activity activity, boolean fullscreen, BaseMessageOptions options,
    WebInterstitialOptions webOptions, HTMLOptions htmlOptions) {
  super(activity, getTheme(activity));

  SizeUtil.init(activity);
  this.activity = activity;
  this.options = options;
  this.webOptions = webOptions;
  this.htmlOptions = htmlOptions;
  if (webOptions != null) {
    isWeb = true;
  }
  if (htmlOptions != null) {
    isHtml = true;
  }
  dialogView = new RelativeLayout(activity);
  RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
      LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  dialogView.setBackgroundColor(Color.TRANSPARENT);
  dialogView.setLayoutParams(layoutParams);

  RelativeLayout view = createContainerView(activity, fullscreen);
  view.setId(108);
  dialogView.addView(view, view.getLayoutParams());

  if ((!isWeb || (webOptions != null && webOptions.hasDismissButton())) && !isHtml) {
    CloseButton closeButton = createCloseButton(activity, fullscreen, view);
    dialogView.addView(closeButton, closeButton.getLayoutParams());
  }

  setContentView(dialogView, dialogView.getLayoutParams());

  dialogView.setAnimation(createFadeInAnimation());

  if (!fullscreen) {
    Window window = getWindow();
    if (window == null) {
      return;
    }
    if (!isHtml) {
      window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
      if (Build.VERSION.SDK_INT >= 14) {
        window.setDimAmount(0.7f);
      }
    } else {
      window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
      window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
          WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
      if (htmlOptions != null &&
          MessageTemplates.Args.HTML_ALIGN_BOTTOM.equals(htmlOptions.getHtmlAlign())) {
        dialogView.setGravity(Gravity.BOTTOM);
      }
    }
  }
}
 
Example 10
Project: CommonFramework   File: MyRecyclerView.java   Source Code and License Vote up 4 votes
@Override
public void setAdapter(Adapter adapter) {
    ArrayList<View> headers = new ArrayList<>();
    ArrayList<View> footers = new ArrayList<>();

    View refreshView = LayoutInflater.from(getContext()).inflate(R.layout.my_refresh, null);
    headerView = refreshView;

    RelativeLayout headerLayout = new RelativeLayout(getContext());
    headerLayout.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    headerLayout.addView(headerView, RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    headerLayout.setGravity(Gravity.BOTTOM);

    status = (TextView) refreshView.findViewById(R.id.status);
    headerView.post(new Runnable() {
        @Override
        public void run() {
            headerViewHeight = headerView.getHeight();
            RelativeLayout.LayoutParams l = (RelativeLayout.LayoutParams) headerView.getLayoutParams();
            l.setMargins(0, -headerViewHeight, 0, 0);
            headerView.requestLayout();
        }
    });
    headers.add(headerLayout);

    LinearLayout footerLayout = new LinearLayout(getContext());
    footerLayout.setGravity(Gravity.CENTER);
    footerLayout.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    footers.add(footerLayout);
    footerLayout.setPadding(0,15,0,15);
    footerLayout.addView(new ProgressBar(getContext(), null, android.R.attr.progressBarStyleSmall));

    TextView text = new TextView(getContext());
    text.setText("正在加载...");
    footerLayout.addView(text);
    footerView=footerLayout;
    footerView.setVisibility(GONE);

    myWrapAdapter = new MyWrapAdapter(adapter, headers, footers);
    super.setAdapter(myWrapAdapter);
}
 
Example 11
Project: EasyAndroid   File: QuickIndexView.java   Source Code and License Vote up 4 votes
/**
 * 初始化,包括必要的 {@link #paint} 等变量初始化,xml属性获取等.
 *
 * @param attrs {@link AttributeSet}
 */
private void init(AttributeSet attrs)
{
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setTextAlign(Paint.Align.CENTER);

    toast = new Toast(context);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);

    toastView = new RelativeLayout(context);
    toastView.setGravity(Gravity.CENTER);
    toast.setView(toastView);

    toastTextView = new TextView(context);
    toastTextView.setGravity(Gravity.CENTER);
    toastView.addView(toastTextView);

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.QuickIndexView);
    textColor = typedArray.getColor(R.styleable.QuickIndexView_textColor, Colors.BLACK);
    quickTextColor = typedArray.getColor(R.styleable.QuickIndexView_quickTextColor, Colors.BLACK);
    topDrawable = typedArray.getDrawable(R.styleable.QuickIndexView_topDrawable);
    bottomDrawable = typedArray.getDrawable(R.styleable.QuickIndexView_bottomDrawable);

    showToast = typedArray.getBoolean(R.styleable.QuickIndexView_showToast, true);
    quickBackground = typedArray.getDrawable(R.styleable.QuickIndexView_quickBackground);
    quickWidth = typedArray.getDimensionPixelSize(R.styleable.QuickIndexView_quickWidth,
            DensityTool.dp2px(context, DEFAULT_WIDTH_DP));
    quickHeight = typedArray.getDimensionPixelSize(R.styleable.QuickIndexView_quickHeight,
            DensityTool.dp2px(context, DEFAULT_WIDTH_DP));

    changeToastViewSize();

    CharSequence[] textArray = typedArray.getTextArray(R.styleable.QuickIndexView_quickLetters);
    if(textArray != null)
    {
        letterList = new ArrayList<>();
        for(CharSequence charSequence : textArray)
        {
            letterList.add(charSequence.toString());
        }
    }
    else
    {
        setLetterArray(ResCompat.getStringArray(context, R.array.defaultQuickIndexViewLetters));
    }

    typedArray.recycle();

    bitmapRect = new Rect();
    outRect = new Rect();
}