Java Code Examples for android.widget.RelativeLayout#setPadding()
The following examples show how to use
android.widget.RelativeLayout#setPadding() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraListAdapter.java From evercam-android with GNU Affero General Public License v3.0 | 6 votes |
/** * 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; }
Example 2
Source File: LayoutInCodeActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
@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); }
Example 3
Source File: MongolToast.java From mongol-library with MIT License | 5 votes |
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; }
Example 4
Source File: MyBanner.java From Aurora with Apache License 2.0 | 5 votes |
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); }
Example 5
Source File: SocialDialogLoginStrategy.java From Android-SDK with MIT License | 5 votes |
@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 ); }
Example 6
Source File: CollectionView.java From TiCollectionView with MIT License | 5 votes |
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); }
Example 7
Source File: EmptyFragment.java From secureit with MIT License | 5 votes |
@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; }
Example 8
Source File: Crouton.java From TiCrouton with MIT License | 4 votes |
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; }
Example 9
Source File: DatePicker.java From Memory-capsule with Apache License 2.0 | 4 votes |
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); }
Example 10
Source File: DatePicker.java From DatePicker with Apache License 2.0 | 4 votes |
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); }
Example 11
Source File: DatePicker.java From nono-android with GNU General Public License v3.0 | 4 votes |
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); }
Example 12
Source File: HuaweiProtectedAppsModule.java From react-native-huawei-protected-apps with MIT License | 4 votes |
@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(); } } }
Example 13
Source File: XBanner.java From XBanner with Apache License 2.0 | 4 votes |
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(); }
Example 14
Source File: BGABanner.java From KUtils-master with Apache License 2.0 | 4 votes |
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(); }
Example 15
Source File: CollectionDetailActivity.java From Expert-Android-Programming with MIT License | 4 votes |
@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(); }
Example 16
Source File: BGABanner.java From KUtils with Apache License 2.0 | 4 votes |
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(); }
Example 17
Source File: BGABanner.java From JD-Test with Apache License 2.0 | 4 votes |
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(); }