У меня есть макет с RecyclerView и BottomNavBar:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
</android.support.v7.widget.RecyclerView>
<android.support.design.widget.BottomNavigationView
android:id="@+id/mainNav"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@color/white"
app:itemTextColor="@color/white"
app:menu="@menu/nav_items">
</android.support.design.widget.BottomNavigationView>
Когда я начинаю свою деятельность, за панелью навигации отображается последнее изображение карты: https://drive.google.com/open?id=1vPwKTwswDSTrf5IJga54fTahUB1j9hni.
Когда я добавляю в RecyclerView строку "android: layout_above =" @ + id / mainNav "", на экране появляется что-то странное, моя ошибка RecyclerView очень большая: https://drive.google.com/open?id=1vI6eOBIf6tQe0rw6wFDDO2phYNvrxRwX. Можете ли вы мне помочь, пожалуйста? <3 </p>
cardview.xml:
<android.support.v7.widget.CardView
android:id="@+id/CardVieww"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="10dp"
android:layout_margin="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/text_nom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:textStyle="bold" />
<TextView
android:id="@+id/text_lieu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"/>
</LinearLayout>
<TextView
android:id="@+id/text_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textStyle="bold"
android:textSize="20sp"
android:padding="10dp" />
<TextView
android:id="@+id/text_heure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:padding="10dp" />
</android.support.v7.widget.CardView>
Planning.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_planning);
db = FirebaseFirestore.getInstance();
db.collection("Planning").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
ListNom.clear();
ListHeure.clear();
ListLieu.clear();
Day.clear();
if (task.isSuccessful()) {
for (DocumentSnapshot document : task.getResult()) {
ListNom.add(document.getString("Nom"));
ListHeure.add(document.getString("Heure"));
ListLieu.add(document.getString("Lieu"));
Day.add(document.getString("Day"));
RecyclerViewAdapter();
}
}
}
});
mainNav = (BottomNavigationView)findViewById(R.id.mainNav);
mainNav.getMenu().getItem(3).setChecked(true);
mainNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()){
case R.id.nav_home :
Intent intent = new Intent(Planning.this, Home.class);
startActivity(intent);
return true;
case R.id.nav_map :
Intent intent2 = new Intent(Planning.this, Localisation.class);
startActivity(intent2);
return true;
case R.id.nav_search :
Intent intent3 = new Intent(Planning.this, Search.class);
startActivity(intent3);
return true;
case R.id.nav_planning :
return true;
case R.id.nav_contact :
Intent intent4 = new Intent(Planning.this, Contact.class);
startActivity(intent4);
return true;
default:
return false;
}
}
});
}
public void RecyclerViewAdapter() {
RecyclerViewAdapter adapter = new RecyclerViewAdapter(ListNom, ListHeure, ListLieu, Day);
RecyclerView myView = (RecyclerView) findViewById(R.id.recyclerview);
myView.setHasFixedSize(true);
myView.setAdapter(adapter);
LinearLayoutManager llm = new LinearLayoutManager(Planning.this);
llm.setOrientation(LinearLayoutManager.VERTICAL);
myView.setLayoutManager(llm);
}
}
RecyclerViewAdapter.java:
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {
public ArrayList<String> ListNom;
public ArrayList<String> ListHeure;
public ArrayList<String> ListLieu;
public ArrayList<String> Day;
public RecyclerViewAdapter (ArrayList<String> ListNom, ArrayList<String> ListHeure, ArrayList<String> ListLieu, ArrayList<String> Day){
this.ListNom= ListNom;
this.ListHeure= ListHeure;
this.ListLieu= ListLieu;
this.Day= Day;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View listItem = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview, parent, false);
return new MyViewHolder(listItem);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
if(Day.get(position) == null){ holder.cardView.setCardBackgroundColor(Color.parseColor("#ffffff")); holder.myTextView.setText(ListNom.get(position)); }else {
holder.cardView.setCardBackgroundColor(Color.parseColor("#cac8a0"));
holder.myTextView4.setText(ListNom.get(position)); }
holder.myTextView2.setText(ListHeure.get(position));
holder.myTextView3.setText(ListLieu.get(position));
if(holder.myTextView3.getText().toString().trim().isEmpty()){ holder.myTextView3.setVisibility(View.GONE); }
}
@Override
public int getItemCount() {
return ListNom.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
private TextView myTextView;
private TextView myTextView2;
private TextView myTextView3;
private TextView myTextView4;
private CardView cardView;
public MyViewHolder(View itemView) {
super(itemView);
myTextView = (TextView)itemView.findViewById(R.id.text_nom);
myTextView2 = (TextView)itemView.findViewById(R.id.text_heure);
myTextView3 = (TextView)itemView.findViewById(R.id.text_lieu);
myTextView4 = (TextView)itemView.findViewById(R.id.text_day);
cardView = (CardView)itemView.findViewById(R.id.CardVieww);
}
}
}