Делаю элемент для RecyclerView
в котором в зависимости от пункта будет светится та или иная ImageView
. Но столкнулся с проблемой если я пишу
holder.image.setVisibility(View.INVISIBLE);
или
holder.image.setImageDrawable(null);
или
holder.image.setMaxHeigh(0);
На месте там где ImageView
стоит которую я пытаюсь скрыть пустое место размером с невидимую ImageView
.
Вот разметка
<LinearLayout
android:layout_weight="4"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content">
<ImageView
android:layout_gravity="center_horizontal"
android:id="@+id/rec_facebook"
android:layout_marginTop="@dimen/padding"
android:layout_marginBottom="@dimen/padding"
android:visibility="invisible"
android:layout_width="@dimen/image"
android:layout_height="@dimen/image"/>
<ImageView
android:layout_gravity="center_horizontal"
android:id="@+id/rec_instagram"
android:layout_marginTop="@dimen/padding"
android:layout_marginBottom="@dimen/padding"
android:visibility="invisible"
android:layout_width="@dimen/image"
android:layout_height="@dimen/image"/>
<ImageView
android:layout_gravity="center_horizontal"
android:id="@+id/rec_telegram"
android:layout_marginTop="@dimen/padding"
android:layout_marginBottom="@dimen/padding"
android:visibility="invisible"
android:layout_width="@dimen/image"
android:layout_height="@dimen/image"/>
<ImageView
android:layout_gravity="center_horizontal"
android:id="@+id/rec_vk"
android:layout_marginTop="@dimen/padding"
android:visibility="invisible"
android:layout_marginBottom="@dimen/padding"
android:layout_width="@dimen/image"
android:layout_height="@dimen/image"/>
<ImageView
android:layout_gravity="center_horizontal"
android:id="@+id/rec_twitter"
android:layout_marginTop="@dimen/padding"
android:visibility="invisible"
android:layout_marginBottom="@dimen/padding"
android:layout_width="@dimen/image"
android:layout_height="@dimen/image"/>
<ImageView
android:layout_gravity="center_horizontal"
android:id="@+id/rec_viber"
android:visibility="invisible"
android:layout_marginTop="@dimen/padding"
android:layout_marginBottom="@dimen/padding"
android:layout_width="@dimen/image"
android:layout_height="@dimen/image"/>
</LinearLayout>
Что я делаю неправильно?
Код адаптера
public class RecycleViewAdapter_Recomend extends RecyclerView.Adapter<RecycleViewAdapter_Recomend.ViewHolder> {
private Context c;
private ArrayList<String> name, text_rec, l_facebook, l_instagram, l_telegram, l_vk, l_twitter, l_viber, logo;
public RecycleViewAdapter_Recomend(Context c, ArrayList<String> name, ArrayList<String> text_rec, ArrayList<String> l_facebook, ArrayList<String> l_instagram, ArrayList<String> l_telegram, ArrayList<String> l_vk, ArrayList<String> l_twitter, ArrayList<String> l_viber, ArrayList<String> logo) {
this.c = c;
this.name = name;
this.text_rec = text_rec;
this.l_facebook = l_facebook;
this.l_instagram = l_instagram;
this.l_telegram = l_telegram;
this.l_vk = l_vk;
this.l_twitter = l_twitter;
this.l_viber = l_viber;
this.logo = logo;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.rec, viewGroup,false);
ViewHolder holder = new ViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(@NonNull final RecycleViewAdapter_Recomend.ViewHolder holder, final int i) {
RequestOptions options = new RequestOptions()
.placeholder(R.color.bg)
.error(R.color.bg)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.priority(Priority.HIGH);
Glide.with(c)
.asBitmap().apply(options)
.load(logo.get(i))
.into(holder.logo);
try{
holder.facebook.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(l_facebook.get(i)));
c.startActivity(intent);
}
});
holder.instagram.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(l_instagram.get(i)));
c.startActivity(intent);
}
});
holder.telegram.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(l_telegram.get(i)));
c.startActivity(intent);
}
});
holder.twitter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(l_twitter.get(i)));
c.startActivity(intent);
}
});
holder.viber.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(l_viber.get(i)));
c.startActivity(intent);
}
});
holder.vk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(l_vk.get(i)));
c.startActivity(intent);
}
});
}catch (Exception e){
e.printStackTrace();
}
holder.facebook.setImageResource(R.drawable.facebook);
holder.instagram.setImageResource(R.drawable.instagram);
holder.telegram.setImageResource(R.drawable.telegram);
holder.twitter.setImageResource(R.drawable.twitter);
holder.vk.setImageResource(R.drawable.vk);
holder.viber.setImageResource(R.drawable.viber);
holder.
switch (i+1){
case 1://Progress
holder.twitter.setImageDrawable(null);
break;
}
holder.text_rec.setHtml(text_rec.get(i));
holder.title.setText(name.get(i));
}
@Override
public int getItemCount() {
return name.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
CardView rec;
ImageView logo, facebook, instagram, telegram, twitter, viber, vk;
TextView title;
HtmlTextView text_rec;
LinearLayout container;
public ViewHolder(@NonNull View i) {
super(i);
rec = i.findViewById(R.id.rec);
logo = i.findViewById(R.id.logo);
facebook = i.findViewById(R.id.rec_facebook);
instagram = i.findViewById(R.id.rec_instagram);
telegram = i.findViewById(R.id.rec_telegram);
twitter = i.findViewById(R.id.rec_twitter);
viber = i.findViewById(R.id.rec_viber);
vk = i.findViewById(R.id.rec_vk);
text_rec = i.findViewById(R.id.html_rec);
title = i.findViewById(R.id.name_rec);
container = i.findViewById(R.id.rec_layout);
}
}
}