當前位置: 首頁>>代碼示例>>Java>>正文


Java RelativeLayout.setPadding方法代碼示例

本文整理匯總了Java中android.widget.RelativeLayout.setPadding方法的典型用法代碼示例。如果您正苦於以下問題:Java RelativeLayout.setPadding方法的具體用法?Java RelativeLayout.setPadding怎麽用?Java RelativeLayout.setPadding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.widget.RelativeLayout的用法示例。


在下文中一共展示了RelativeLayout.setPadding方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getLayout

import android.widget.RelativeLayout; //導入方法依賴的package包/類
private View getLayout() {
    int horizontalPadding = (int) getTypedValueInDP(context, DEFAULT_HORIZONTAL_PADDING);
    int verticalPadding = (int) getTypedValueInDP(context, DEFAULT_VERTICAL_PADDING);
    RelativeLayout rootLayout = new RelativeLayout(context);
    rootLayout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);
    rootLayout.setBackgroundDrawable(getShape());
    rootLayout.addView(getTextView());
    return rootLayout;
}
 
開發者ID:suragch,項目名稱:mongol-library,代碼行數:10,代碼來源:MongolToast.java

示例2: initView

import android.widget.RelativeLayout; //導入方法依賴的package包/類
private void initView() {
    //初始化RecyclerView
    mRecyclerView = new SpeedRecyclerView(mContext);
    mRecyclerView.setId(R.id.banner_recycler);
    //以matchParent的方式將RecyclerView填充到控件容器中
    addView(mRecyclerView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    //創建指示器容器的相對布局
    RelativeLayout indicatorContainerRl = new RelativeLayout(mContext);
    //設置指示器容器Padding
    indicatorContainerRl.setPadding(UiUtils.dip2px(mContext,2), 0, UiUtils.dip2px(mContext,8), 0);
    //初始化指示器容器的布局參數
    LayoutParams indicatorContainerLp = new LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    // 設置指示器容器內的子view的布局方式
    indicatorContainerLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    indicatorContainerLp.addRule(RelativeLayout.BELOW,R.id.banner_recycler);
    //將指示器容器添加到父View中
    addView(indicatorContainerRl, indicatorContainerLp);
    //初始化存放點的線性布局
    mPointContainerLl = new LinearLayout(mContext);
    //設置線性布局的id
    mPointContainerLl.setId(R.id.banner_pointContainerId);
    //設置線性布局的方向
    mPointContainerLl.setOrientation(LinearLayout.HORIZONTAL);
    //設置點容器的布局參數
    LayoutParams pointContainerLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    pointContainerLp.addRule(RelativeLayout.CENTER_IN_PARENT);
    //將點容器存放到指示器容器中
    indicatorContainerRl.addView(mPointContainerLl, pointContainerLp);
}
 
開發者ID:Zweihui,項目名稱:Aurora,代碼行數:30,代碼來源:MyBanner.java

示例3: create

import android.widget.RelativeLayout; //導入方法依賴的package包/類
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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:69,代碼來源:ContactsListviewItemLayout.java

示例4: initView

import android.widget.RelativeLayout; //導入方法依賴的package包/類
private void initView(Context context) {
    RelativeLayout pointContainerRl = new RelativeLayout(context);
    if (Build.VERSION.SDK_INT >= 16) {
        pointContainerRl.setBackground(mPointContainerBackgroundDrawable);
    } else {
        pointContainerRl.setBackgroundDrawable(mPointContainerBackgroundDrawable);
    }
    pointContainerRl.setPadding(mPointContainerLeftRightPadding, mPointTopBottomMargin, mPointContainerLeftRightPadding, mPointTopBottomMargin);
    LayoutParams pointContainerLp = new LayoutParams(RMP, RWC);
    // 處理圓點在頂部還是底部
    if ((mPointGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.TOP) {
        pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    } else {
        pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    }
    addView(pointContainerRl, pointContainerLp);


    LayoutParams indicatorLp = new LayoutParams(RWC, RWC);
    indicatorLp.addRule(CENTER_VERTICAL);
    if (mIsNumberIndicator) {
        mNumberIndicatorTv = new TextView(context);
        mNumberIndicatorTv.setId(R.id.banner_indicatorId);
        mNumberIndicatorTv.setGravity(Gravity.CENTER_VERTICAL);
        mNumberIndicatorTv.setSingleLine(true);
        mNumberIndicatorTv.setEllipsize(TextUtils.TruncateAt.END);
        mNumberIndicatorTv.setTextColor(mNumberIndicatorTextColor);
        mNumberIndicatorTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mNumberIndicatorTextSize);
        mNumberIndicatorTv.setVisibility(View.INVISIBLE);
        if (mNumberIndicatorBackground != null) {
            if (Build.VERSION.SDK_INT >= 16) {
                mNumberIndicatorTv.setBackground(mNumberIndicatorBackground);
            } else {
                mNumberIndicatorTv.setBackgroundDrawable(mNumberIndicatorBackground);
            }
        }
        pointContainerRl.addView(mNumberIndicatorTv, indicatorLp);
    } else {
        mPointRealContainerLl = new LinearLayout(context);
        mPointRealContainerLl.setId(R.id.banner_indicatorId);
        mPointRealContainerLl.setOrientation(LinearLayout.HORIZONTAL);
        mPointRealContainerLl.setGravity(Gravity.CENTER_VERTICAL);
        pointContainerRl.addView(mPointRealContainerLl, indicatorLp);
    }

    LayoutParams tipLp = new LayoutParams(RMP, RWC);
    tipLp.addRule(CENTER_VERTICAL);
    mTipTv = new TextView(context);
    mTipTv.setGravity(Gravity.CENTER_VERTICAL);
    mTipTv.setSingleLine(true);
    mTipTv.setEllipsize(TextUtils.TruncateAt.END);
    mTipTv.setTextColor(mTipTextColor);
    mTipTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTipTextSize);
    pointContainerRl.addView(mTipTv, tipLp);

    int horizontalGravity = mPointGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    // 處理圓點在左邊、右邊還是水平居中
    if (horizontalGravity == Gravity.LEFT) {
        indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        tipLp.addRule(RelativeLayout.RIGHT_OF, R.id.banner_indicatorId);
        mTipTv.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    } else if (horizontalGravity == Gravity.RIGHT) {
        indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
    } else {
        indicatorLp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
    }

    showPlaceholder();
}
 
開發者ID:devzwy,項目名稱:KUtils,代碼行數:72,代碼來源:BGABanner.java

示例5: initView

import android.widget.RelativeLayout; //導入方法依賴的package包/類
private void initView(Context context) {
    RelativeLayout pointContainerRl = new RelativeLayout(context);
    if (Build.VERSION.SDK_INT >= 16) {
        pointContainerRl.setBackground(mPointContainerBackgroundDrawable);
    } else {
        pointContainerRl.setBackgroundDrawable(mPointContainerBackgroundDrawable);
    }
    pointContainerRl.setPadding(mPointContainerLeftRightPadding, mPointTopBottomMargin, mPointContainerLeftRightPadding, mPointTopBottomMargin);
    LayoutParams pointContainerLp = new LayoutParams(RMP, RWC);
    // 處理圓點在頂部還是底部
    if ((mPointGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.TOP) {
        pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    } else {
        pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    }
    addView(pointContainerRl, pointContainerLp);


    LayoutParams indicatorLp = new LayoutParams(RWC, RWC);
    indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    if (mIsNumberIndicator) {
        mNumberIndicatorTv = new TextView(context);
        mNumberIndicatorTv.setId(R.id.banner_indicatorId);
        mNumberIndicatorTv.setGravity(Gravity.CENTER_VERTICAL);
        mNumberIndicatorTv.setSingleLine(true);
        mNumberIndicatorTv.setEllipsize(TextUtils.TruncateAt.END);
        mNumberIndicatorTv.setTextColor(mNumberIndicatorTextColor);
        mNumberIndicatorTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mNumberIndicatorTextSize);
        mNumberIndicatorTv.setVisibility(View.INVISIBLE);
        if (mNumberIndicatorBackground != null) {
            if (Build.VERSION.SDK_INT >= 16) {
                mNumberIndicatorTv.setBackground(mNumberIndicatorBackground);
            } else {
                mNumberIndicatorTv.setBackgroundDrawable(mNumberIndicatorBackground);
            }
        }
        pointContainerRl.addView(mNumberIndicatorTv, indicatorLp);
    } else {
        mPointRealContainerLl = new LinearLayout(context);
        mPointRealContainerLl.setId(R.id.banner_indicatorId);
        mPointRealContainerLl.setOrientation(LinearLayout.HORIZONTAL);
        mPointRealContainerLl.setGravity(Gravity.CENTER_VERTICAL);


        pointContainerRl.addView(mPointRealContainerLl, indicatorLp);
    }

    LayoutParams tipLp = new LayoutParams(RMP, RWC);
    tipLp.addRule(CENTER_VERTICAL);
    mTipTv = new TextView(context);
    mTipTv.setGravity(Gravity.CENTER_VERTICAL);
    mTipTv.setSingleLine(true);
    mTipTv.setEllipsize(TextUtils.TruncateAt.END);
    mTipTv.setTextColor(mTipTextColor);
    mTipTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTipTextSize);
    pointContainerRl.addView(mTipTv, tipLp);

    int horizontalGravity = mPointGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    // 處理圓點在左邊、右邊還是水平居中
    if (horizontalGravity == Gravity.LEFT) {
        indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        tipLp.addRule(RelativeLayout.RIGHT_OF, R.id.banner_indicatorId);
        mTipTv.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    } else if (horizontalGravity == Gravity.RIGHT) {
        indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
    } else {
        indicatorLp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
    }

    showPlaceholder();
}
 
開發者ID:liu-xiao-dong,項目名稱:JD-Test,代碼行數:74,代碼來源:BGABanner.java

示例6: onCreate

import android.widget.RelativeLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_collection_details);


    title = (TextView) findViewById(R.id.title);
    toolbar_lay = (RelativeLayout) findViewById(R.id.toolbar_lay);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        toolbar_lay.setPadding(0, CommonFunctions.getStatusBarHeight(context), 0, 0);
    }

    item = (CollectionItem) getIntent().getSerializableExtra(Constant.DATA);

    scrollView = (NestedScrollView) findViewById(R.id.scrollView);
    fadeShadow = (View) findViewById(R.id.fadeShadow);
    checkImage = (ImageView) findViewById(R.id.checkImage);

    scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            checkVisibility();
        }
    });

    checkImage.post(new Runnable() {
        @Override
        public void run() {
            checkVisibility();
        }
    });
    checkVisibility();

    name = (TextView) findViewById(R.id.name);
    saves = (TextView) findViewById(R.id.saves);
    details = (TextView) findViewById(R.id.details);
    saveButton = (TextView) findViewById(R.id.saveButton);

    //Might
    mightList = new ArrayList<>();
    mightAdapter = new CollectionPlaceAdapter(context, mightList);
    mightAdapter.setClickListener(new CollectionPlaceAdapter.ClickListener() {
        @Override
        public void onItemClickListener(View v, int pos) {
            gotoDetailsActivity(pos);
        }
    });

    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new GridLayoutManager(context, 2));
    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setAdapter(mightAdapter);

    setCollectionDetails();
}
 
開發者ID:PacktPublishing,項目名稱:Expert-Android-Programming,代碼行數:56,代碼來源:CollectionDetailActivity.java


注:本文中的android.widget.RelativeLayout.setPadding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。