本文整理汇总了Java中android.widget.RelativeLayout.setBackgroundResource方法的典型用法代码示例。如果您正苦于以下问题:Java RelativeLayout.setBackgroundResource方法的具体用法?Java RelativeLayout.setBackgroundResource怎么用?Java RelativeLayout.setBackgroundResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.RelativeLayout
的用法示例。
在下文中一共展示了RelativeLayout.setBackgroundResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startEditMode
import android.widget.RelativeLayout; //导入方法依赖的package包/类
private void startEditMode(RecyclerView parent) {
this.isEditMode = true;
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
View view = parent.getChildAt(i);
if (view != null) {
ImageView imgEdit = (ImageView) view.findViewById(R.id.edit_tip);
RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.item_group_id);
if (layout != null) {
layout.setBackgroundResource(R.drawable.channel_wall_item_selecter_bg);
}
if (imgEdit != null) {
if (((Integer) imgEdit.getTag()).intValue() == 0) {
imgEdit.setBackgroundResource(2130837812);
} else {
imgEdit.setBackgroundResource(2130837811);
}
imgEdit.setVisibility(0);
}
}
}
}
示例2: getView
import android.widget.RelativeLayout; //导入方法依赖的package包/类
@Override
public View getView(final int position, final View convertView, ViewGroup parentView) {
final RelativeLayout songListLayout = (RelativeLayout) songListInflater.inflate(R.layout.list_item_song_fixed, parentView, false);
if (position % 2 - 1 == 0) {
songListLayout.setBackgroundResource(R.color.gray_2);
} else {
songListLayout.setBackgroundResource(R.color.gray_3);
}
// Get the parts of a song layout
//ImageView songItemIcon = (ImageView) songListLayout.findViewById(R.id.song_icon);
TextView songItemName = (TextView) songListLayout.findViewById(R.id.song_name);
TextView songItemArtist = (TextView) songListLayout.findViewById(R.id.song_composer);
// Set the parts equal to the corresponding song
SongData songItem = songDataList.get(position);
//songItemIcon.setImageDrawable(songItem.getSongCover());
songItemName.setText(songItem.getSongName());
songItemArtist.setText(songItem.getSongArtist());
// Set position as tag
songListLayout.setTag(position);
return songListLayout;
}
示例3: getView
import android.widget.RelativeLayout; //导入方法依赖的package包/类
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.custom_menu, parent, false
);
}
Menu currentMenu = getItem(position);
TextView baslik = (TextView) listItemView.findViewById(R.id.menu_name);
baslik.setText(currentMenu.getBaslik());
RelativeLayout bg = (RelativeLayout) listItemView.findViewById(R.id.label);
bg.setBackgroundResource(currentMenu.getImage());
return listItemView;
}
示例4: initView
import android.widget.RelativeLayout; //导入方法依赖的package包/类
private void initView() {
mRlSpinner = (RelativeLayout) findViewById(R.id.rl_spinner);
mTvSelected = (TextView) findViewById(R.id.tv_selected);
mIvIndicate = (ImageView) findViewById(R.id.iv_indicate);
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) mTvSelected.getLayoutParams();
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mIvIndicate.getLayoutParams();
params1.leftMargin = mLeftMargin;
params2.rightMargin = mRightMargin;
mRlSpinner.setBackgroundResource(R.drawable.solid_tran_stroke_gray);
mTvSelected.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
mTvSelected.setTextColor(mTextColor);
this.setOnClickListener(this);
}
示例5: onCreateContent
import android.widget.RelativeLayout; //导入方法依赖的package包/类
@Override
protected void onCreateContent(QMUIDialog dialog, ViewGroup parent) {
mMainLayout = new RelativeLayout(mContext);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.topMargin = QMUIResHelper.getAttrDimen(mContext, hasTitle() ? R.attr.qmui_dialog_edit_content_padding_top : R.attr.qmui_dialog_content_padding_top_when_no_title);
lp.leftMargin = QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_padding_horizontal);
lp.rightMargin = QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_padding_horizontal);
lp.bottomMargin = QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_edit_content_padding_bottom);
mMainLayout.setBackgroundResource(R.drawable.qmui_edittext_bg_border_bottom);
mMainLayout.setLayoutParams(lp);
if(mTransformationMethod!=null){
mEditText.setTransformationMethod(mTransformationMethod);
}else{
mEditText.setInputType(mInputType);
}
mEditText.setBackgroundResource(0);
mEditText.setPadding(0, 0, 0, QMUIDisplayHelper.dpToPx(5));
RelativeLayout.LayoutParams editLp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
editLp.addRule(RelativeLayout.LEFT_OF, mRightImageView.getId());
editLp.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
if (mPlaceholder != null) {
mEditText.setHint(mPlaceholder);
}
mMainLayout.addView(mEditText, createEditTextLayoutParams());
mMainLayout.addView(mRightImageView, createRightIconLayoutParams());
parent.addView(mMainLayout);
}
示例6: getView
import android.widget.RelativeLayout; //导入方法依赖的package包/类
@Override
public View getView(final int position, final View convertView, ViewGroup parentView) {
final RelativeLayout songListLayout = (RelativeLayout) songListInflater.inflate(R.layout.list_item_song, parentView, false);
if (position % 2 - 1 == 0) {
songListLayout.setBackgroundResource(R.color.gray_2);
} else {
songListLayout.setBackgroundResource(R.color.gray_3);
}
// Get the parts of a song layout
//ImageView songItemIcon = (ImageView) songListLayout.findViewById(R.id.song_icon);
ImageView songOverflowIcon = (ImageView) songListLayout.findViewById(R.id.song_overflow);
TextView songItemName = (TextView) songListLayout.findViewById(R.id.song_name);
TextView songItemArtist = (TextView) songListLayout.findViewById(R.id.song_composer);
// Set the parts equal to the corresponding song
SongData songItem = songDataList.get(position);
//songItemIcon.setImageDrawable(songItem.getSongCover());
songItemName.setText(songItem.getSongName());
songItemArtist.setText(songItem.getSongArtist());
// Set on click listener for overflow
songOverflowIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((MainActivity) activity).showChoiceMenu(songListLayout, position);
}
});
// Set position as tag
songListLayout.setTag(position);
return songListLayout;
}
示例7: getView
import android.widget.RelativeLayout; //导入方法依赖的package包/类
@Override
public View getView(final int position, View convertView, ViewGroup parentView) {
final RelativeLayout playlistLayout = (RelativeLayout) playlistInflater.inflate(R.layout.list_item_playlist, parentView, false);
if (position % 2 - 1 == 0) {
playlistLayout.setBackgroundResource(R.color.gray_2);
} else {
playlistLayout.setBackgroundResource(R.color.gray_3);
}
// Get the parts of a playlist layout
//ImageView playlistItemIcon = (ImageView) playlistLayout.findViewById(R.id.playlist_icon);
ImageView playlistOverflowIcon = (ImageView) playlistLayout.findViewById(R.id.playlist_overflow);
TextView playlistItemName = (TextView) playlistLayout.findViewById(R.id.playlist_name);
TextView playlistItemSize = (TextView) playlistLayout.findViewById(R.id.playlist_size);
// Set the parts equal to the corresponding playlist
PlaylistData playlistItem = playlistDataList.get(position);
//playlistItemIcon.setImageDrawable(playlistItem.getPlaylistIcon());
playlistItemName.setText(playlistItem.getPlaylistName());
if (playlistItem.getNumSongs() != 1) {
playlistItemSize.setText(Integer.toString(playlistItem.getNumSongs()) + " songs");
} else {
playlistItemSize.setText(Integer.toString(playlistItem.getNumSongs()) + " song");
}
// Set on click listener for overflow
playlistOverflowIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((PlaylistMenuActivity) activity).showChoiceMenu(playlistLayout, position);
}
});
// Set position as tag
playlistLayout.setTag(position);
return playlistLayout;
}
示例8: getView
import android.widget.RelativeLayout; //导入方法依赖的package包/类
@Override
public View getView(final int position, final View convertView, ViewGroup parentView) {
relativeLayout = (RelativeLayout) layoutInflater.inflate(R.layout.list_item_album, parentView, false);
if (position % 2 - 1 == 0) {
relativeLayout.setBackgroundResource(R.color.gray_2);
} else {
relativeLayout.setBackgroundResource(R.color.gray_3);
}
// Get parts of layout
ImageView albumCover = (ImageView) relativeLayout.findViewById(R.id.album_cover);
TextView albumName = (TextView) relativeLayout.findViewById(R.id.album_name);
TextView albumSize = (TextView) relativeLayout.findViewById(R.id.album_size);
// Get values
String name = keyList.get(position);
Drawable cover = songAlbumList.get(name).get(0).getSongCover();
RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(activity.getResources(), ((BitmapDrawable) cover).getBitmap());
drawable.setCornerRadius(50.0f);
int size = songAlbumList.get(name).size();
// Set values
albumCover.setImageDrawable(drawable);
albumName.setText(name);
if (size == 1) {
albumSize.setText("1 song");
} else {
albumSize.setText(Integer.toString(size) + " songs");
}
// Return
relativeLayout.setTag(position);
return relativeLayout;
}
示例9: getView
import android.widget.RelativeLayout; //导入方法依赖的package包/类
@Override
public View getView(final int position, final View convertView, ViewGroup parentView) {
relativeLayout = (RelativeLayout) layoutInflater.inflate(R.layout.list_item_artist, parentView, false);
if (position % 2 - 1 == 0) {
relativeLayout.setBackgroundResource(R.color.gray_2);
} else {
relativeLayout.setBackgroundResource(R.color.gray_3);
}
// Get parts of layout
TextView artistName = (TextView) relativeLayout.findViewById(R.id.artist_name);
TextView artistSize = (TextView) relativeLayout.findViewById(R.id.artist_size);
// Get values
String name = keyList.get(position);
int size = songArtistList.get(name).size();
// Set values
artistName.setText(name);
if (size == 1) {
artistSize.setText("1 song");
} else {
artistSize.setText(Integer.toString(size) + " songs");
}
// Return
relativeLayout.setTag(position);
return relativeLayout;
}
示例10: getView
import android.widget.RelativeLayout; //导入方法依赖的package包/类
@Override
public View getView(final int position, final View convertView, ViewGroup parentView) {
relativeLayout = (RelativeLayout) layoutInflater.inflate(R.layout.list_item_genre, parentView, false);
if (position % 2 - 1 == 0) {
relativeLayout.setBackgroundResource(R.color.gray_2);
} else {
relativeLayout.setBackgroundResource(R.color.gray_3);
}
// Get parts of layout
TextView genreName = (TextView) relativeLayout.findViewById(R.id.genre_name);
TextView genreSize = (TextView) relativeLayout.findViewById(R.id.genre_size);
// Get values
String name = keyList.get(position);
int size = songGenreList.get(name).size();
// Set values
genreName.setText(name);
if (size == 1) {
genreSize.setText("1 song");
} else {
genreSize.setText(Integer.toString(size) + " songs");
}
// Return
relativeLayout.setTag(position);
return relativeLayout;
}
示例11: onCreate
import android.widget.RelativeLayout; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// InputStream ims = null;
// try {
// ims = getAssets().open("pic.png");
// } catch (IOException e) {
// e.printStackTrace();
// }
// Drawable d = Drawable.createFromStream(ims, null);
RelativeLayout ll = (RelativeLayout) findViewById(R.id.rl);
ll.setBackgroundResource(R.drawable.pic);
et = (EditText) findViewById(R.id.et1);
}
示例12: onCreateContent
import android.widget.RelativeLayout; //导入方法依赖的package包/类
@Override
protected void onCreateContent(QMUIDialog dialog, ViewGroup parent) {
mMainLayout = new RelativeLayout(mContext);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.topMargin = QMUIResHelper.getAttrDimen(mContext, hasTitle() ? R.attr.qmui_dialog_edit_content_padding_top : R.attr.qmui_dialog_content_padding_top_when_no_title);
lp.leftMargin = QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_padding_horizontal);
lp.rightMargin = QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_padding_horizontal);
lp.bottomMargin = QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_edit_content_padding_bottom);
mMainLayout.setBackgroundResource(R.drawable.qmui_edittext_bg_border_bottom);
mMainLayout.setLayoutParams(lp);
if (mTransformationMethod != null) {
mEditText.setTransformationMethod(mTransformationMethod);
} else {
mEditText.setInputType(mInputType);
}
mEditText.setBackgroundResource(0);
mEditText.setPadding(0, 0, 0, QMUIDisplayHelper.dpToPx(5));
RelativeLayout.LayoutParams editLp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
editLp.addRule(RelativeLayout.LEFT_OF, mRightImageView.getId());
editLp.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
if (mPlaceholder != null) {
mEditText.setHint(mPlaceholder);
}
mMainLayout.addView(mEditText, createEditTextLayoutParams());
mMainLayout.addView(mRightImageView, createRightIconLayoutParams());
parent.addView(mMainLayout);
}
示例13: getImageWrapper
import android.widget.RelativeLayout; //导入方法依赖的package包/类
public static RelativeLayout getImageWrapper(Context context, MenuObject menuItem, int menuItemSize,
View.OnClickListener onCLick, View.OnLongClickListener onLongClick,
boolean showDivider) {
RelativeLayout imageWrapper = new RelativeLayout(context);
LinearLayout.LayoutParams imageWrapperLayoutParams = new LinearLayout.LayoutParams(menuItemSize, menuItemSize);
imageWrapper.setLayoutParams(imageWrapperLayoutParams);
imageWrapper.setOnClickListener(onCLick);
imageWrapper.setOnLongClickListener(onLongClick);
imageWrapper.addView(Utils.getItemImageButton(context, menuItem));
if (showDivider) {
imageWrapper.addView(getDivider(context, menuItem));
}
if (menuItem.getBgColor() != 0) {
imageWrapper.setBackgroundColor(menuItem.getBgColor());
} else if (menuItem.getBgDrawable() != null) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
imageWrapper.setBackgroundDrawable(menuItem.getBgDrawable());
} else {
imageWrapper.setBackground(menuItem.getBgDrawable());
}
} else if (menuItem.getBgResource() != 0) {
imageWrapper.setBackgroundResource(menuItem.getBgResource());
} else {
imageWrapper.setBackgroundColor(context.getResources().getColor(R.color.menu_item_background));
}
return imageWrapper;
}
示例14: createToastView
import android.widget.RelativeLayout; //导入方法依赖的package包/类
private static View createToastView(Context context) {
RelativeLayout root = new RelativeLayout(context);
root.setTag("root");
if (isSupport()) {
root.setBackgroundResource(context.getResources().getIdentifier("colorAccent", "color", context.getPackageName()));
}
//root.setBackgroundColor(Color.RED);
WindowManager.LayoutParams rootParams = new WindowManager.LayoutParams(-1, -2);
rootParams.gravity = Gravity.TOP;
root.setLayoutParams(rootParams);
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.HORIZONTAL);
if (isSupport()) {
layout.setBackgroundResource(context.getResources().getIdentifier("colorAccent", "color", context.getPackageName()));
}
// layout.setBackgroundResource(android.R.color.holo_red_dark);
// layout.setVerticalGravity(Gravity.VERTICAL_GRAVITY_MASK);
final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(-2, -2);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.setLayoutParams(params);
layout.setMinimumHeight(getMinHeight(context));
ImageView imageView = new ImageView(context);
imageView.setTag("image");
imageView.setVisibility(View.GONE);
TextView textView = new TextView(context);
textView.setTag("text");
textView.setTextColor(Color.WHITE);
final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
layoutParams.setMargins(getMinHeight(context, 10), 0, 0, 0);
layoutParams.gravity = Gravity.CENTER_VERTICAL;
layout.addView(imageView, layoutParams);
layout.addView(textView, layoutParams);
root.addView(layout);
return root;
}
示例15: UpdateBackGround
import android.widget.RelativeLayout; //导入方法依赖的package包/类
private void UpdateBackGround(int weatherCode) {
toolbar.setBackgroundResource(codeToColor[weatherCode]);
RelativeLayout layout = (RelativeLayout)findViewById(R.id.content_main);
layout.setBackgroundResource(codeToColor[weatherCode]);
StatusBarUtils.setWindowStatusBarColor(this, codeToColor[weatherCode]);
}