下面列出了android.widget.RelativeLayout#setTag ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View view) {
final int size = ITEMS.size();
for(int i = 0; i < size; i++){
LayoutInflater.from(getContext()).inflate(R.layout.bottom_item_icon_text_layout, mBottomBar);
final RelativeLayout item = (RelativeLayout) mBottomBar.getChildAt(i);
//设置每一个item的点击事件
item.setTag(i);
item.setOnClickListener(this);
//图标
final IconTextView itemIcon = (IconTextView) item.getChildAt(0);
//文字
final AppCompatTextView itemTitle = (AppCompatTextView) item.getChildAt(1);
final BottomTabBean bean = TAB_BEANS.get(i);
//初始化数据
itemIcon.setText(bean.getIcon());
itemTitle.setText(bean.getTitle());
if (i == mIndexDelegate) {
itemIcon.setTextColor(mClickedColor);
itemTitle.setTextColor(mClickedColor);
}
}
final ISupportFragment[] delegateArray = ITEM_DELEGATES.toArray(new ISupportFragment[size]);
//加载多个同级根Fragment,类似Wechat, QQ主页的场景
getSupportDelegate().loadMultipleRootFragment(R.id.bottom_bar_delegate_container, mIndexDelegate, delegateArray);
}
/**
* 生成图片View
* @return view
*/
private RelativeLayout createImageLayout() {
RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.edit_imageview, null);
layout.setTag(viewTagIndex++);
View closeView = layout.findViewById(R.id.image_close);
closeView.setVisibility(GONE);
HyperImageView imageView = layout.findViewById(R.id.edit_imageView);
imageView.setOnClickListener(btnListener);
return layout;
}
public void init(RelativeLayout audioPlayer, Message message) {
synchronized (AudioPlayer.LOCK) {
audioPlayer.setTag(message);
if (init(ViewHolder.get(audioPlayer), message)) {
this.audioPlayerLayouts.addWeakReferenceTo(audioPlayer);
executor.execute(() -> this.stopRefresher(true));
} else {
this.audioPlayerLayouts.removeWeakReferenceTo(audioPlayer);
}
}
}
public static ViewHolder get(RelativeLayout audioPlayer) {
ViewHolder viewHolder = (ViewHolder) audioPlayer.getTag(R.id.TAG_AUDIO_PLAYER_VIEW_HOLDER);
if (viewHolder == null) {
viewHolder = new ViewHolder();
viewHolder.runtime = audioPlayer.findViewById(R.id.runtime);
viewHolder.progress = audioPlayer.findViewById(R.id.progress);
viewHolder.playPause = audioPlayer.findViewById(R.id.play_pause);
audioPlayer.setTag(R.id.TAG_AUDIO_PLAYER_VIEW_HOLDER, viewHolder);
}
return viewHolder;
}
NewMessageRecyclerViewHolder(
@NonNull RelativeLayout itemView,
FriendAddOnClick clickListener
) {
super(itemView);
mUserName = itemView.findViewById(R.id.new_message_item_name);
mUserImage = itemView.findViewById(R.id.new_message_item_img);
mBase = itemView.findViewById(R.id.new_message_item);
this.clickListener = clickListener;
itemView.setOnClickListener(this);
itemView.setTag(this);
}
private View createItemView(int position, View view) {
RelativeLayout parent = new RelativeLayout(getContext());
parent.setTag(position);
parent.setOnClickListener(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
parent.addView(view, params);
return parent;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// Get the monster for the current row
Monster monster = mMonsterCursor.getMonster();
AssetManager manager = context.getAssets();
// Set up the text view
TextView monsterNameTextView = (TextView) view.findViewById(R.id.item_label);
ImageView monsterImage = (ImageView) view.findViewById(R.id.item_image);
RelativeLayout itemLayout = (RelativeLayout) view.findViewById(R.id.listitem);
String cellText = monster.getName();
String cellImage = "icons_monster/" + monster.getFileLocation();
monsterNameTextView.setText(cellText);
// Read a Bitmap from Assets
try {
InputStream open = manager.open(cellImage);
Bitmap bitmap = BitmapFactory.decodeStream(open);
// Assign the bitmap to an ImageView in this layout
monsterImage.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
itemLayout.setTag(monster.getId());
itemLayout.setOnClickListener(new MonsterClickListener(context, monster.getId()));
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// Get the monster for the current row
Location location = mLocationCursor.getLocation();
AssetManager manager = context.getAssets();
RelativeLayout listLayout = (RelativeLayout) view
.findViewById(R.id.listitem);
// Set up the text view
TextView locationNameTextView = (TextView) view
.findViewById(R.id.item_label);
ImageView locationImage = (ImageView) view
.findViewById(R.id.item_image);
String cellText = location.getName();
String cellImage = "icons_location/" + location.getFileLocationMini();
locationNameTextView.setText(cellText);
// Read a Bitmap from Assets
locationImage.setTag(location.getId());
new LoadImage(locationImage, cellImage).execute();
listLayout.setTag(location.getId());
listLayout.setOnClickListener(new LocationClickListener(context, location.getId()));
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// Get the weapon for the current row
Weapon weapon = mWeaponCursor.getWeapon();
// Set up the text view
RelativeLayout weaponLayout = (RelativeLayout) view.findViewById(R.id.listitem);
weaponLayout.setTag(weapon.getId());
weaponLayout.setOnClickListener(new WeaponClickListener(context, weapon.getId()));
TextView weaponView = (TextView) view.findViewById(R.id.name_text);
String cellWeaponText = weapon.getName();
if(weapon.getCreationCost() > 0){
cellWeaponText = cellWeaponText + "\u2605";
}
weaponView.setText(cellWeaponText);
View arrowView = (View) view.findViewById(R.id.arrow);
arrowView.setVisibility(view.GONE);
if ((weapon.getId() <= weaponId) && (weapon.getWFinal() == 0)) {
arrowView.setVisibility(view.VISIBLE);
}
if (weapon.getId() == weaponId) {
weaponView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
}
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
BookmarkFolder folder = bookmarkFolders.get(arg0);
if (ignore!=null && ignore.getInternalName().equals(folder.getInternalName())){
return ((LinearLayout) MainActivity.inflater.inflate(R.layout.null_item, null));
}
RelativeLayout RL = (RelativeLayout) MainActivity.inflater.inflate(
R.layout.bookmarkfolder_item, null);
if (Properties.appProp.darkTheme) {
((TextView)(RL.findViewById(R.id.bookmark_title))).setTextColor(Color.WHITE);
((ImageView)(RL.findViewById(R.id.bookmark_icon))).setColorFilter(Color.WHITE, Mode.SRC_ATOP);
} else {
// Use sight theme
}
((TextView) RL.findViewById(R.id.bookmark_title)).setText(folder
.getDisplayName());
RL.setTag(folder.getInternalName());
((ImageView) RL.findViewById(R.id.bookmark_icon))
.setImageResource(R.drawable.ic_action_collection);
return RL;
}
public void init(RelativeLayout audioPlayer, Message message) {
synchronized (AudioPlayer.LOCK) {
audioPlayer.setTag(message);
if (init(ViewHolder.get(audioPlayer), message)) {
this.audioPlayerLayouts.addWeakReferenceTo(audioPlayer);
executor.execute(()-> this.stopRefresher(true));
} else {
this.audioPlayerLayouts.removeWeakReferenceTo(audioPlayer);
}
}
}
public static ViewHolder get(RelativeLayout audioPlayer) {
ViewHolder viewHolder = (ViewHolder) audioPlayer.getTag(R.id.TAG_AUDIO_PLAYER_VIEW_HOLDER);
if (viewHolder == null) {
viewHolder = new ViewHolder();
viewHolder.runtime = audioPlayer.findViewById(R.id.runtime);
viewHolder.progress = audioPlayer.findViewById(R.id.progress);
viewHolder.playPause = audioPlayer.findViewById(R.id.play_pause);
audioPlayer.setTag(R.id.TAG_AUDIO_PLAYER_VIEW_HOLDER, viewHolder);
}
return viewHolder;
}
public void addItem(String itemText) {
RelativeLayout itemLayout = (RelativeLayout) View.inflate(this.mContext, R.layout.anim_tab_item, null);
((TextView) itemLayout.getChildAt(0)).setText(itemText);
itemLayout.setTag(Integer.valueOf(this.mTotalItemsCount));
if (this.mTotalItemsCount == 0) {
itemLayout.setSelected(true);
}
itemLayout.setOnClickListener(this.mItemClickListener);
this.mTotalItemsCount = (1 + this.mTotalItemsCount);
this.mItemsLayout.addView(itemLayout, new LinearLayout.LayoutParams(0, -1, 1.0F));
}
public LifeIndexViewHolder(View itemView, CityWeatherPresenter presenter) {
super(itemView);
//ButterKnife.bind(this, itemView);
tvTitleName = (TextView)itemView.findViewById(R.id.tv_cv_title_name);
rlLifeIndex1 = (RelativeLayout)itemView.findViewById(R.id.rl_city_weather_life_index_1);
ivIcon1 = (ImageView)itemView.findViewById(R.id.iv_city_weather_life_index_icon1);
tvName1 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_name1);
tvBrief1 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_brief1);
ivArrow1 = (ImageView)itemView.findViewById(R.id.iv_city_weather_life_index_arrow1);
tvDesc1 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_desc1);
rlLifeIndex2 = (RelativeLayout)itemView.findViewById(R.id.rl_city_weather_life_index_2);
ivIcon2 = (ImageView)itemView.findViewById(R.id.iv_city_weather_life_index_icon2);
tvName2 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_name2);
tvBrief2 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_brief2);
ivArrow2 = (ImageView)itemView.findViewById(R.id.iv_city_weather_life_index_arrow2);
tvDesc2 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_desc2);
rlLifeIndex3 = (RelativeLayout)itemView.findViewById(R.id.rl_city_weather_life_index_3);
ivIcon3 = (ImageView)itemView.findViewById(R.id.iv_city_weather_life_index_icon3);
tvName3 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_name3);
tvBrief3 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_brief3);
ivArrow3 = (ImageView)itemView.findViewById(R.id.iv_city_weather_life_index_arrow3);
tvDesc3 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_desc3);
rlLifeIndex4 = (RelativeLayout)itemView.findViewById(R.id.rl_city_weather_life_index_4);
ivIcon4 = (ImageView)itemView.findViewById(R.id.iv_city_weather_life_index_icon4);
tvName4 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_name4);
tvBrief4 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_brief4);
ivArrow4 = (ImageView)itemView.findViewById(R.id.iv_city_weather_life_index_arrow4);
tvDesc4 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_desc4);
rlLifeIndex5 = (RelativeLayout)itemView.findViewById(R.id.rl_city_weather_life_index_5);
ivIcon5 = (ImageView)itemView.findViewById(R.id.iv_city_weather_life_index_icon5);
tvName5 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_name5);
tvBrief5 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_brief5);
ivArrow5 = (ImageView)itemView.findViewById(R.id.iv_city_weather_life_index_arrow5);
tvDesc5 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_desc5);
rlLifeIndex6 = (RelativeLayout)itemView.findViewById(R.id.rl_city_weather_life_index_6);
ivIcon6 = (ImageView)itemView.findViewById(R.id.iv_city_weather_life_index_icon6);
tvName6 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_name6);
tvBrief6 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_brief6);
ivArrow6 = (ImageView)itemView.findViewById(R.id.iv_city_weather_life_index_arrow6);
tvDesc6 = (TextView)itemView.findViewById(R.id.tv_city_weather_life_index_desc6);
rlLifeIndex1.setOnClickListener(this);
rlLifeIndex1.setTag(presenter);
rlLifeIndex2.setOnClickListener(this);
rlLifeIndex2.setTag(presenter);
rlLifeIndex3.setOnClickListener(this);
rlLifeIndex3.setTag(presenter);
rlLifeIndex4.setOnClickListener(this);
rlLifeIndex4.setTag(presenter);
rlLifeIndex5.setOnClickListener(this);
rlLifeIndex5.setTag(presenter);
rlLifeIndex6.setOnClickListener(this);
rlLifeIndex6.setTag(presenter);
}
@Override
protected void convert(BaseViewHolder holder, TrendArticle entity) {
holder.setText(R.id.last_compiled_time, formatTime(entity.getPublishTime()));
holder.setText(R.id.collection_tag, getSubjectTitle(entity));
String avatarUrl = getAvatar(entity);
if (!TextUtils.isEmpty(avatarUrl)) {
UniversalDraweeView draweeViewAuthorAvatar = holder.getView(R.id.author_avatar);
draweeViewAuthorAvatar.setImageURI(avatarUrl);
}
TextView tvAuthorName = holder.getView(R.id.author_name);
TextView tvTitle = holder.getView(R.id.title);
TextView tvExtraInfo = holder.getView(R.id.extra_info);
UniversalDraweeView draweeViewImage = holder.getView(R.id.image);
RelativeLayout rlAvatarName = holder.getView(R.id.avatar_name);
FrameLayout flCollectionTagContainer = holder.getView(R.id.collection_tag_container);
boolean shouldSetSelected = ArticleDetailDao.isRead(entity.getId());
String userNickname = getNickname(entity);
if (!TextUtils.isEmpty(userNickname)) {
tvAuthorName.setText(userNickname);
tvAuthorName.setSelected(shouldSetSelected);
}
tvTitle.setText(entity.getTitle());
tvTitle.setSelected(shouldSetSelected);
tvExtraInfo.setText(getExtraInfo(entity));
tvExtraInfo.setCompoundDrawablesWithIntrinsicBounds(entity.isHasVideo() ? mDefaultVideoIcon : null, null, null, null);
if (TextUtils.isEmpty(entity.getImage())) {
draweeViewImage.setVisibility(View.GONE);
} else {
draweeViewImage.setVisibility(View.VISIBLE);
String thumbUrl = ImageUtils.format(entity.getImage(), DisplayInfo.dp2px(80));
draweeViewImage.setImageURI(thumbUrl);
}
rlAvatarName.setTag(holder.getLayoutPosition());
rlAvatarName.setOnClickListener(this);
flCollectionTagContainer.setTag(holder.getLayoutPosition());
flCollectionTagContainer.setOnClickListener(this);
if (TextUtils.isEmpty(getSubjectTitle(entity))) {
flCollectionTagContainer.setVisibility(View.GONE);
} else {
flCollectionTagContainer.setVisibility(View.VISIBLE);
}
holder.setTag(R.id.root_view, holder.getLayoutPosition());
holder.setOnClickListener(R.id.root_view, this);
}
private void onLoadFinished(List<Device> devices) {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
setListShown(false);
loadAvailableDevices();
}
}, 5000);
if (devices.size() == 0) {
setListShown(true);
return;
}
// Set the new devices in the adapter.
for (int i = 0; i < devices.size(); i++) {
if (!containDevice(devices.get(i))) {
RelativeLayout view = (RelativeLayout) getActivity().getLayoutInflater().inflate(R.layout.configure_device_list_item, null, false);
TextView text1 = view.findViewById(android.R.id.text1);
TextView text2 = view.findViewById(android.R.id.text2);
String deviceName = devices.get(i).getModelName();
String friendlyName = devices.get(i).getUserDeviceName();
if (friendlyName != null && !friendlyName.isEmpty()) {
deviceName = friendlyName + " (" + deviceName + ")";
}
text1.setText(deviceName);
text2.setText("SN: " + devices.get(i).getSerialNumber());
view.setTag(devices.get(i));
view.setOnClickListener(mClickListener);
mList.addView(view);
}
}
// The list should now be shown.
if (isResumed()) {
setListShown(true);
} else {
setListShown(true);
//setListShownNoAnimation(true);
}
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// Get the decoration for the current row
Decoration decoration = mDecorationCursor.getDecoration();
RelativeLayout itemLayout = (RelativeLayout) view.findViewById(R.id.listitem);
// Set up the text view
ImageView itemImageView = (ImageView) view.findViewById(R.id.item_image);
TextView decorationNameTextView = (TextView) view.findViewById(R.id.item);
TextView skill1TextView = (TextView) view.findViewById(R.id.skill1);
TextView skill1amtTextView = (TextView) view.findViewById(R.id.skill1_amt);
TextView skill2TextView = (TextView) view.findViewById(R.id.skill2);
TextView skill2amtTextView = (TextView) view.findViewById(R.id.skill2_amt);
String decorationNameText = decoration.getName();
String skill1Text = decoration.getSkill1Name();
String skill1amtText = "" + decoration.getSkill1Point();
String skill2Text = decoration.getSkill2Name();
String skill2amtText = "";
if (decoration.getSkill2Point() != 0) {
skill2amtText = skill2amtText + decoration.getSkill2Point();
}
Drawable i = null;
String cellImage = "icons_items/" + decoration.getFileLocation();
try {
i = Drawable.createFromStream(
context.getAssets().open(cellImage), null);
} catch (IOException e) {
e.printStackTrace();
}
itemImageView.setImageDrawable(i);
decorationNameTextView.setText(decorationNameText);
skill1TextView.setText(skill1Text);
skill1amtTextView.setText(skill1amtText);
skill2TextView.setVisibility(View.GONE);
skill2amtTextView.setVisibility(View.GONE);
if (!skill2amtText.equals("")) {
skill2TextView.setText(skill2Text);
skill2amtTextView.setText(skill2amtText);
skill2TextView.setVisibility(View.VISIBLE);
skill2amtTextView.setVisibility(View.VISIBLE);
}
itemLayout.setTag(decoration.getId());
if (fromAsb) {
boolean fitsInArmor = (decoration.getNumSlots() <= maxSlots);
view.setEnabled(fitsInArmor);
// Set the jewel image to be translucent if disabled
// TODO: If a way to use alpha with style selectors exist, use that instead
itemImageView.setAlpha((fitsInArmor) ? 1.0f : 0.5f);
if (fitsInArmor) {
itemLayout.setOnClickListener(new DecorationClickListener(context, decoration.getId(), true, activity));
}
}
else {
itemLayout.setOnClickListener(new DecorationClickListener(context, decoration.getId()));
}
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// Get the item for the current row
HuntingReward huntingReward = mHuntingRewardCursor.getHuntingReward();
// Set up the text view
RelativeLayout itemLayout = (RelativeLayout) view
.findViewById(R.id.listitem);
ImageView itemImageView = (ImageView) view
.findViewById(R.id.item_image);
TextView itemTextView = (TextView) view.findViewById(R.id.item);
TextView methodTextView = (TextView) view.findViewById(R.id.method);
TextView amountTextView = (TextView) view.findViewById(R.id.amount);
TextView percentageTextView = (TextView) view
.findViewById(R.id.percentage);
String cellItemText = huntingReward.getItem().getName();
String cellConditionText = huntingReward.getCondition();
String cellTraitText = huntingReward.getMonster().getTrait();
int cellAmountText = huntingReward.getStackSize();
int cellPercentageText = huntingReward.getPercentage();
if (!cellTraitText.equals("")) {
cellConditionText = cellConditionText + " (" + cellTraitText + ")";
}
itemTextView.setText(cellItemText);
methodTextView.setText(cellConditionText);
amountTextView.setText("" + cellAmountText);
String percent = "" + cellPercentageText + "%";
percentageTextView.setText(percent);
Drawable i = null;
String cellImage = "icons_items/" + huntingReward.getItem().getFileLocation();
try {
i = Drawable.createFromStream(
context.getAssets().open(cellImage), null);
} catch (IOException e) {
e.printStackTrace();
}
itemImageView.setImageDrawable(i);
itemLayout.setTag(huntingReward.getItem().getId());
itemLayout.setOnClickListener(new ItemClickListener(context, huntingReward.getItem().getId()));
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// Get the item for the current row
HuntingReward huntingReward = mHuntingRewardCursor.getHuntingReward();
// Set up the text view
RelativeLayout itemLayout = (RelativeLayout) view.findViewById(R.id.listitem);
TextView rankTextView = (TextView) view.findViewById(R.id.rank);
TextView monsterTextView = (TextView) view.findViewById(R.id.monster);
TextView methodTextView = (TextView) view.findViewById(R.id.method);
TextView amountTextView = (TextView) view.findViewById(R.id.amount);
TextView percentageTextView = (TextView) view
.findViewById(R.id.percentage);
ImageView monsterImageView = (ImageView) view.findViewById(R.id.monster_image);
String cellRankText = huntingReward.getRank();
String cellMonsterText = huntingReward.getMonster().getName();
String cellMethodText = huntingReward.getCondition();
int cellAmountText = huntingReward.getStackSize();
int cellPercentageText = huntingReward.getPercentage();
rankTextView.setText(cellRankText);
monsterTextView.setText(cellMonsterText);
methodTextView.setText(cellMethodText);
amountTextView.setText("" + cellAmountText);
String percent = "" + cellPercentageText + "%";
percentageTextView.setText(percent);
itemLayout.setTag(huntingReward.getMonster().getId());
itemLayout.setOnClickListener(new MonsterClickListener(context,
huntingReward.getMonster().getId()));
Drawable i = null;
String cellImage = "icons_monster/"
+ huntingReward.getMonster().getFileLocation();
try {
i = Drawable.createFromStream(
context.getAssets().open(cellImage), null);
} catch (IOException e) {
e.printStackTrace();
}
monsterImageView.setImageDrawable(i);
}