android.widget.RelativeLayout#setPadding ( )源码实例Demo

下面列出了android.widget.RelativeLayout#setPadding ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: evercam-android   文件: CameraListAdapter.java
/**
 * Remove offline icon for selected camera that is showing as title
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = super.getView(position, convertView, parent);
    ImageView offlineIcon = (ImageView) view.findViewById(R.id.spinner_offline_icon);
    offlineIcon.setVisibility(View.GONE);

    //Title text should be white
    CheckedTextView titleTextView = (CheckedTextView) view.findViewById(R.id.spinner_camera_name_text);
    titleTextView.setTextColor(Color.WHITE);

    //Make spinner text fit landscape too
    RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.list_spinner_layout);
    layout.setPadding(10, 0, 10, 0);

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

  RelativeLayout.LayoutParams lp;
  lp =
    new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                    LinearLayout.LayoutParams.MATCH_PARENT);

  RelativeLayout.LayoutParams textViewLP;
  textViewLP = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT,
    RelativeLayout.LayoutParams.WRAP_CONTENT);

  Resources res = getResources();
  int hpad = res.getDimensionPixelSize(R.dimen.activity_horizontal_margin);
  int vpad = res.getDimensionPixelSize(R.dimen.activity_vertical_margin);

  RelativeLayout rl = new RelativeLayout(this);
  rl.setPadding(hpad, vpad, hpad, vpad);

  TextView myTextView = new TextView(this);
  myTextView.setText("Hello World!");

  rl.addView(myTextView, textViewLP);

  addContentView(rl, lp);
}
 
源代码3 项目: mongol-library   文件: MongolToast.java
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;
}
 
源代码4 项目: Aurora   文件: MyBanner.java
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);
}
 
源代码5 项目: secureit   文件: EmptyFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {    	
	
    if ((savedInstanceState != null) && savedInstanceState.containsKey(CONTENT)) {
        mContent = savedInstanceState.getString(CONTENT);
    }
	
    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;
}
 
源代码6 项目: TiCollectionView   文件: CollectionView.java
private void layoutSearchView(TiViewProxy searchView) {
	TiUIView search = searchView.getOrCreateView();
	RelativeLayout layout = new RelativeLayout(proxy.getActivity());
	layout.setGravity(Gravity.NO_GRAVITY);
	layout.setPadding(0, 0, 0, 0);
	addSearchLayout(layout, searchView, search);
	setNativeView(layout);	
}
 
源代码7 项目: Android-SDK   文件: SocialDialogLoginStrategy.java
@Override
public void createLayout()
{
  RelativeLayout mainContainer = new RelativeLayout( getContext() );
  android.widget.ImageView closeImage = createCloseImage();
  RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT );
  layoutParams.addRule( RelativeLayout.ALIGN_PARENT_RIGHT );
  layoutParams.addRule( RelativeLayout.ALIGN_PARENT_TOP );
  int closeImageWidth = closeImage.getDrawable().getIntrinsicWidth() / 2;
  mainContainer.setPadding( closeImageWidth, closeImageWidth, closeImageWidth, closeImageWidth );

  dialog.addContentView( mainContainer, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) );
  mainContainer.addView( getWebView() );
  mainContainer.addView( closeImage, layoutParams );
}
 
源代码8 项目: Memory-capsule   文件: DatePicker.java
public DatePicker(Context context, AttributeSet attrs) {
    super(context, attrs);
    mTManager = DPTManager.getInstance();
    mLManager = DPLManager.getInstance();

    // 设置排列方向为竖向
    setOrientation(VERTICAL);

    LayoutParams llParams =
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    // 标题栏根布局
    RelativeLayout rlTitle = new RelativeLayout(context);
    rlTitle.setBackgroundColor(mTManager.colorTitleBG());
    int rlTitlePadding = MeasureUtil.dp2px(context, 10);
    rlTitle.setPadding(rlTitlePadding, rlTitlePadding, rlTitlePadding, rlTitlePadding);

    // 周视图根布局
    LinearLayout llWeek = new LinearLayout(context);
    llWeek.setBackgroundColor(mTManager.colorTitleBG());
    llWeek.setOrientation(HORIZONTAL);
    int llWeekPadding = MeasureUtil.dp2px(context, 5);
    llWeek.setPadding(0, llWeekPadding, 0, llWeekPadding);
    LayoutParams lpWeek = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpWeek.weight = 1;

    // 标题栏子元素布局参数
    RelativeLayout.LayoutParams lpYear =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpYear.addRule(RelativeLayout.CENTER_VERTICAL);
    RelativeLayout.LayoutParams lpMonth =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpMonth.addRule(RelativeLayout.CENTER_IN_PARENT);
    RelativeLayout.LayoutParams lpEnsure =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpEnsure.addRule(RelativeLayout.CENTER_VERTICAL);
    lpEnsure.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

    // --------------------------------------------------------------------------------标题栏
    // 年份显示
    tvYear = new TextView(context);
    tvYear.setText("2015");
    tvYear.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tvYear.setTextColor(mTManager.colorTitle());

    // 月份显示
    tvMonth = new TextView(context);
    tvMonth.setText("六月");
    tvMonth.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    tvMonth.setTextColor(mTManager.colorTitle());

    // 确定显示
    tvEnsure = new TextView(context);
    tvEnsure.setText(mLManager.titleEnsure());
    tvEnsure.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tvEnsure.setTextColor(mTManager.colorTitle());
    tvEnsure.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != onDateSelectedListener) {
                onDateSelectedListener.onDateSelected(monthView.getDateSelected());
            }
        }
    });

    rlTitle.addView(tvYear, lpYear);
    rlTitle.addView(tvMonth, lpMonth);
    rlTitle.addView(tvEnsure, lpEnsure);

    addView(rlTitle, llParams);

    // --------------------------------------------------------------------------------周视图
    for (int i = 0; i < mLManager.titleWeek().length; i++) {
        TextView tvWeek = new TextView(context);
        tvWeek.setText(mLManager.titleWeek()[i]);
        tvWeek.setGravity(Gravity.CENTER);
        tvWeek.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        tvWeek.setTextColor(mTManager.colorTitle());
        llWeek.addView(tvWeek, lpWeek);
    }
    addView(llWeek, llParams);

    // ------------------------------------------------------------------------------------月视图
    monthView = new MonthView(context);
    monthView.setOnDateChangeListener(new MonthView.OnDateChangeListener() {
        @Override
        public void onMonthChange(int month) {
            tvMonth.setText(mLManager.titleMonth()[month - 1]);
        }

        @Override
        public void onYearChange(int year) {
            String tmp = String.valueOf(year);
            if (tmp.startsWith("-")) {
                tmp = tmp.replace("-", mLManager.titleBC());
            }
            tvYear.setText(tmp);
        }
    });
    addView(monthView, llParams);
}
 
源代码9 项目: JD-Test   文件: BGABanner.java
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();
}
 
源代码10 项目: KUtils   文件: BGABanner.java
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();
}
 
@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();
}
 
源代码12 项目: KUtils-master   文件: BGABanner.java
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();
}
 
源代码13 项目: XBanner   文件: XBanner.java
private void initView() {

        /*设置指示器背景容器*/
        RelativeLayout pointContainerRl = new RelativeLayout(getContext());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            pointContainerRl.setBackground(mPointContainerBackgroundDrawable);
        } else {
            pointContainerRl.setBackgroundDrawable(mPointContainerBackgroundDrawable);
        }

        /*设置内边距*/
        pointContainerRl.setPadding(mPointContainerLeftRightPadding, mPointTopBottomPading, mPointContainerLeftRightPadding, mPointTopBottomPading);

        /*设定指示器容器布局及位置*/
        mPointContainerLp = new LayoutParams(RMP, RWC);
        mPointContainerLp.addRule(mPointContainerPosition);
        if (mIsClipChildrenMode) {
            mPointContainerLp.setMargins(mClipChildrenLeftRightMargin, 0, mClipChildrenLeftRightMargin, mClipChildrenTopBottomMargin);
        }
        addView(pointContainerRl, mPointContainerLp);
        mPointRealContainerLp = new LayoutParams(RWC, RWC);
        /*设置指示器容器*/
        if (mIsNumberIndicator) {
            mNumberIndicatorTv = new TextView(getContext());
            mNumberIndicatorTv.setId(R.id.xbanner_pointId);
            mNumberIndicatorTv.setGravity(Gravity.CENTER);
            mNumberIndicatorTv.setSingleLine(true);
            mNumberIndicatorTv.setEllipsize(TextUtils.TruncateAt.END);
            mNumberIndicatorTv.setTextColor(mTipTextColor);
            mNumberIndicatorTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTipTextSize);
            mNumberIndicatorTv.setVisibility(View.INVISIBLE);
            if (mNumberIndicatorBackground != null) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    mNumberIndicatorTv.setBackground(mNumberIndicatorBackground);
                } else {
                    mNumberIndicatorTv.setBackgroundDrawable(mNumberIndicatorBackground);
                }
            }
            pointContainerRl.addView(mNumberIndicatorTv, mPointRealContainerLp);
        } else {
            mPointRealContainerLl = new LinearLayout(getContext());
            mPointRealContainerLl.setOrientation(LinearLayout.HORIZONTAL);
            mPointRealContainerLl.setId(R.id.xbanner_pointId);
            pointContainerRl.addView(mPointRealContainerLl, mPointRealContainerLp);
        }

        /*设置指示器是否可见*/
        if (mPointRealContainerLl != null) {
            if (mPointsIsVisible) {
                mPointRealContainerLl.setVisibility(View.VISIBLE);
            } else {
                mPointRealContainerLl.setVisibility(View.GONE);
            }
        }

        /*设置提示语*/
        LayoutParams pointLp = new LayoutParams(RMP, RWC);
        pointLp.addRule(CENTER_VERTICAL);

        if (mIsShowTips) {
            mTipTv = new TextView(getContext());
            mTipTv.setGravity(Gravity.CENTER_VERTICAL);
            mTipTv.setSingleLine(true);
            if (mIsTipsMarquee) {
                mTipTv.setEllipsize(TextUtils.TruncateAt.MARQUEE);
                mTipTv.setMarqueeRepeatLimit(3);
                mTipTv.setSelected(true);
            } else {
                mTipTv.setEllipsize(TextUtils.TruncateAt.END);
            }
            mTipTv.setTextColor(mTipTextColor);
            mTipTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTipTextSize);
            pointContainerRl.addView(mTipTv, pointLp);
        }

        /*设置指示器布局位置*/
        if (CENTER == mPointPosition) {
            mPointRealContainerLp.addRule(RelativeLayout.CENTER_HORIZONTAL);
            pointLp.addRule(RelativeLayout.LEFT_OF, R.id.xbanner_pointId);
        } else if (LEFT == mPointPosition) {
            mPointRealContainerLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            if (mTipTv != null) {
                mTipTv.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
            }
            pointLp.addRule(RelativeLayout.RIGHT_OF, R.id.xbanner_pointId);
        } else if (RIGHT == mPointPosition) {
            mPointRealContainerLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            pointLp.addRule(RelativeLayout.LEFT_OF, R.id.xbanner_pointId);
        }
        setBannerPlaceholderDrawable();
    }
 
@ReactMethod
public void AlertIfHuaweiDevice(String title, String message, String dontShowAgainText, String positiveText, String negativeText) {
    // read "do not show again" flag
    final SharedPreferences settings = this.getCurrentActivity().getSharedPreferences("ProtectedApps",Context.MODE_PRIVATE);
    final String saveIfSkip = "skipProtectedAppsMessage";
    boolean skipMessage = settings.getBoolean(saveIfSkip, false);
    // Show dialog only when "do not show again" hasn't been enabled yet
    if (!skipMessage) {
        final SharedPreferences.Editor editor = settings.edit();
        Intent intent = new Intent();
        // Check if intent of the Huawei protected apps activity is callable
        intent.setClassName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity");
        if (isCallable(intent)) {
            // Prepare dialog
            final AppCompatCheckBox dontShowAgain = new AppCompatCheckBox(this.getCurrentActivity());
            dontShowAgain.setText(dontShowAgainText);
            dontShowAgain.setLeft(20);
            dontShowAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    editor.putBoolean(saveIfSkip, isChecked);
                    editor.apply();
                }
            });

            final RelativeLayout layout = new RelativeLayout(this.getCurrentActivity());
            layout.setPadding(50,50,0,0);
            layout.addView(dontShowAgain);

            new AlertDialog.Builder(this.getCurrentActivity())
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setTitle(title)
                    .setMessage(message)
                    .setView(layout)
                    .setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // Launch huawei Protected Apps Activity
                            huaweiProtectedApps();
                        }
                    })
                    .setNegativeButton(negativeText, null)
                    .show();
        } else {
            // Save "do not show again" flag automatically for non-Huawei devices to prevent unnecessary checks
            editor.putBoolean(saveIfSkip, true);
            editor.apply();
        }
    }
}
 
源代码15 项目: nono-android   文件: DatePicker.java
public DatePicker(Context context, AttributeSet attrs) {
    super(context, attrs);
    mTManager = DPTManager.getInstance();
    mLManager = DPLManager.getInstance();

    // 设置排列方向为竖向
    setOrientation(VERTICAL);

    LayoutParams llParams =
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    // 标题栏根布局
     rlTitle = new RelativeLayout(context);
    rlTitle.setBackgroundColor(mTManager.colorTitleBG());
    int rlTitlePadding = MeasureUtil.dp2px(context, 8);
    rlTitle.setPadding(rlTitlePadding, rlTitlePadding, rlTitlePadding, rlTitlePadding);

    // 周视图根布局
     llWeek = new LinearLayout(context);
    llWeek.setBackgroundColor(mTManager.colorTitleBG());
    llWeek.setOrientation(HORIZONTAL);
    int llWeekPadding = MeasureUtil.dp2px(context, 4);
    llWeek.setPadding(0, llWeekPadding, 0, llWeekPadding);
    LayoutParams lpWeek = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpWeek.weight = 1;

    // 标题栏子元素布局参数
    RelativeLayout.LayoutParams lpYear =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpYear.addRule(RelativeLayout.CENTER_VERTICAL);
    RelativeLayout.LayoutParams lpMonth =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpMonth.addRule(RelativeLayout.CENTER_IN_PARENT);
    RelativeLayout.LayoutParams lpEnsure =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpEnsure.addRule(RelativeLayout.CENTER_VERTICAL);
    lpEnsure.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

    // --------------------------------------------------------------------------------标题栏
    // 年份显示
    tvYear = new TextView(context);
    tvYear.setText("2015");
    tvYear.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tvYear.setTextColor(mTManager.colorTitle());

    // 月份显示
    tvMonth = new TextView(context);
    tvMonth.setText("六月");
    tvMonth.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    tvMonth.setTextColor(mTManager.colorTitle());

    // 确定显示
    tvEnsure = new TextView(context);
    tvEnsure.setText(mLManager.titleEnsure());
    tvEnsure.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tvEnsure.setTextColor(mTManager.colorTitle());
    tvEnsure.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != onDateSelectedListener) {
                onDateSelectedListener.onDateSelected(monthView.getDateSelected());
            }
        }
    });

    rlTitle.addView(tvYear, lpYear);
    rlTitle.addView(tvMonth, lpMonth);
    rlTitle.addView(tvEnsure, lpEnsure);

    addView(rlTitle, llParams);

    // --------------------------------------------------------------------------------周视图
    for (int i = 0; i < mLManager.titleWeek().length; i++) {
        TextView tvWeek = new TextView(context);
        tvWeek.setText(mLManager.titleWeek()[i]);
        tvWeek.setGravity(Gravity.CENTER);
        tvWeek.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        tvWeek.setTextColor(mTManager.colorTitle());
        llWeek.addView(tvWeek, lpWeek);
    }
    addView(llWeek, llParams);

    // ------------------------------------------------------------------------------------月视图
    monthView = new MonthView(context);
    monthView.setOnDateChangeListener(new MonthView.OnDateChangeListener() {
        @Override
        public void onMonthChange(int month) {
            tvMonth.setText(mLManager.titleMonth()[month - 1]);
        }

        @Override
        public void onYearChange(int year) {
            String tmp = String.valueOf(year);
            if (tmp.startsWith("-")) {
                tmp = tmp.replace("-", mLManager.titleBC());
            }
            tvYear.setText(tmp);
        }
    });
    addView(monthView, llParams);
}
 
源代码16 项目: DatePicker   文件: DatePicker.java
public DatePicker(Context context, AttributeSet attrs) {
    super(context, attrs);
    mTManager = DPTManager.getInstance();
    mLManager = DPLManager.getInstance();

    // 设置排列方向为竖向
    setOrientation(VERTICAL);

    LayoutParams llParams =
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    // 标题栏根布局
    RelativeLayout rlTitle = new RelativeLayout(context);
    rlTitle.setBackgroundColor(mTManager.colorTitleBG());
    int rlTitlePadding = MeasureUtil.dp2px(context, 10);
    rlTitle.setPadding(rlTitlePadding, rlTitlePadding, rlTitlePadding, rlTitlePadding);

    // 周视图根布局
    LinearLayout llWeek = new LinearLayout(context);
    llWeek.setBackgroundColor(mTManager.colorTitleBG());
    llWeek.setOrientation(HORIZONTAL);
    int llWeekPadding = MeasureUtil.dp2px(context, 5);
    llWeek.setPadding(0, llWeekPadding, 0, llWeekPadding);
    LayoutParams lpWeek = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpWeek.weight = 1;

    // 标题栏子元素布局参数
    RelativeLayout.LayoutParams lpYear =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpYear.addRule(RelativeLayout.CENTER_VERTICAL);
    RelativeLayout.LayoutParams lpMonth =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpMonth.addRule(RelativeLayout.CENTER_IN_PARENT);
    RelativeLayout.LayoutParams lpEnsure =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpEnsure.addRule(RelativeLayout.CENTER_VERTICAL);
    lpEnsure.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

    // --------------------------------------------------------------------------------标题栏
    // 年份显示
    tvYear = new TextView(context);
    tvYear.setText("2015");
    tvYear.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tvYear.setTextColor(mTManager.colorTitle());

    // 月份显示
    tvMonth = new TextView(context);
    tvMonth.setText("六月");
    tvMonth.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    tvMonth.setTextColor(mTManager.colorTitle());

    // 确定显示
    tvEnsure = new TextView(context);
    tvEnsure.setText(mLManager.titleEnsure());
    tvEnsure.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tvEnsure.setTextColor(mTManager.colorTitle());
    tvEnsure.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != onDateSelectedListener) {
                onDateSelectedListener.onDateSelected(monthView.getDateSelected());
            }
        }
    });

    rlTitle.addView(tvYear, lpYear);
    rlTitle.addView(tvMonth, lpMonth);
    rlTitle.addView(tvEnsure, lpEnsure);

    addView(rlTitle, llParams);

    // --------------------------------------------------------------------------------周视图
    for (int i = 0; i < mLManager.titleWeek().length; i++) {
        TextView tvWeek = new TextView(context);
        tvWeek.setText(mLManager.titleWeek()[i]);
        tvWeek.setGravity(Gravity.CENTER);
        tvWeek.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        tvWeek.setTextColor(mTManager.colorTitle());
        llWeek.addView(tvWeek, lpWeek);
    }
    addView(llWeek, llParams);

    // ------------------------------------------------------------------------------------月视图
    monthView = new MonthView(context);
    monthView.setOnDateChangeListener(new MonthView.OnDateChangeListener() {
        @Override
        public void onMonthChange(int month) {
            tvMonth.setText(mLManager.titleMonth()[month - 1]);
        }

        @Override
        public void onYearChange(int year) {
            String tmp = String.valueOf(year);
            if (tmp.startsWith("-")) {
                tmp = tmp.replace("-", mLManager.titleBC());
            }
            tvYear.setText(tmp);
        }
    });
    addView(monthView, llParams);
}
 
源代码17 项目: TiCrouton   文件: Crouton.java
private RelativeLayout initializeContentView(final Resources resources) {
  RelativeLayout contentView = new RelativeLayout(this.activity);
  contentView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
      RelativeLayout.LayoutParams.MATCH_PARENT));

  // set padding
  int padding = this.style.paddingInPixels;

  // if a padding dimension has been set, this will overwrite any padding
  // in pixels
  if (this.style.paddingDimensionResId > 0) {
    padding = resources.getDimensionPixelSize(this.style.paddingDimensionResId);
  }
  contentView.setPadding(padding, padding, padding, padding);

  // only setup image if one is requested
  ImageView image = null;
  if ((null != this.style.imageDrawable) || (0 != this.style.imageResId)) {
    image = initializeImageView();
    contentView.addView(image, image.getLayoutParams());
  }

  TextView text = initializeTextView(resources);

  RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
      RelativeLayout.LayoutParams.WRAP_CONTENT);
  if (null != image) {
    textParams.addRule(RelativeLayout.RIGHT_OF, image.getId());
  }

  if ((this.style.gravity & Gravity.CENTER) != 0) {
    textParams.addRule(RelativeLayout.CENTER_IN_PARENT);
  } else if ((this.style.gravity & Gravity.CENTER_VERTICAL) != 0) {
    textParams.addRule(RelativeLayout.CENTER_VERTICAL);
  } else if ((this.style.gravity & Gravity.CENTER_HORIZONTAL) != 0) {
    textParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
  }

  contentView.addView(text, textParams);
  return contentView;
}