Home > Net >  My cardview is going off screen even in wrapcontent
My cardview is going off screen even in wrapcontent

Time:06-10

MY PROBLEM -

my cardview is going over the screen(can be seen in the image) even if the says matchparent.

my database node Please help....... is this a bug or smth?

What am i doing = i m trying to retrieve the data from firebase in a recycler view, the data is being retrieved but the item of the recyclerview is giving problem, as the cardview is half outside the screen even if the cardview is set to matchparent and wrapcontent please help if possible

My recycler Item

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
    android:id="@ id/Cdate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hi"
    android:textSize="50dp"
    android:layout_gravity="center"
    android:layout_marginTop="20dp"/>
    </androidx.cardview.widget.CardView>

my Adapterclass

package com.sjsbhints.pdfmanager;

  import android.view.LayoutInflater;
   import android.view.View;
     import android.view.ViewGroup;
     import android.widget.TextView;

    import androidx.annotation.NonNull;
    import androidx.recyclerview.widget.RecyclerView;

  import com.firebase.ui.database.FirebaseRecyclerAdapter;
  import com.firebase.ui.database.FirebaseRecyclerOptions;

  public class CAdapter extends FirebaseRecyclerAdapter<Cmodel,CAdapter.myViewHolder> {

/**
 * Initialize a {@link RecyclerView.Adapter} that listens to a Firebase query. See
 * {@link FirebaseRecyclerOptions} for configuration options.
 *
 * @param options
 */
public CAdapter(@NonNull FirebaseRecyclerOptions<Cmodel> options) {
    super(options);
}

@Override
protected void onBindViewHolder(@NonNull myViewHolder holder, int position, @NonNull Cmodel model) {

  //         if(model.Cdate.isEmpty()){
     //             holder.Cdate.setText("Null");
       //         }
        holder.Cdate.setText(model.getCdate());
     //        holder.Cheading.setText(model.getCheading());
     //       holder.Cbody.setText(model.getCbody());

}

@NonNull
@Override
public myViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.circular_item,parent,false);

    return new myViewHolder(view);
}

class myViewHolder extends RecyclerView.ViewHolder{

    TextView Cdate,Cheading,Cbody,Ndate,Nheading,Nsheading,Nbody,Tdate,Tsubject,Ttopic,Ttdate;

    public myViewHolder(@NonNull View itemView) {
        super(itemView);

          Cdate = itemView.findViewById(R.id.Cdate);
    //            Cheading = itemView.findViewById(R.id.cheading);
  //            Cbody = itemView.findViewById(R.id.cbody);
                }
               }
                }

my model class

package com.sjsbhints.pdfmanager;

public class Cmodel {

String Cdate,Cheading,Cbody,Ndate,Nheading,Nsheading,Nbody,Tdate,Tsubject,Ttopic,Ttdate;

Cmodel(){
}

public Cmodel(String cdate, String cheading, String cbody, String ndate, String nheading, String nsheading, String nbody, String tdate, String tsubject, String ttopic, String ttdate) {
    Cdate = cdate;
    Cheading = cheading;
    Cbody = cbody;
    Ndate = ndate;
    Nheading = nheading;
    Nsheading = nsheading;
    Nbody = nbody;
    Tdate = tdate;
    Tsubject = tsubject;
    Ttopic = ttopic;
    Ttdate = ttdate;
}

public String getCdate() {
    return Cdate;
}

public void setCdate(String cdate) {
    Cdate = cdate;
}

public String getCheading() {
    return Cheading;
}

public void setCheading(String cheading) {
    Cheading = cheading;
}

public String getCbody() {
    return Cbody;
}

public void setCbody(String cbody) {
    Cbody = cbody;
}

public String getNdate() {
    return Ndate;
}

public void setNdate(String ndate) {
    Ndate = ndate;
}

public String getNheading() {
    return Nheading;
}

public void setNheading(String nheading) {
    Nheading = nheading;
}

public String getNsheading() {
    return Nsheading;
}

public void setNsheading(String nsheading) {
    Nsheading = nsheading;
}

public String getNbody() {
    return Nbody;
}

public void setNbody(String nbody) {
    Nbody = nbody;
}

public String getTdate() {
    return Tdate;
}

public void setTdate(String tdate) {
    Tdate = tdate;
}

public String getTsubject() {
    return Tsubject;
}

public void setTsubject(String tsubject) {
    Tsubject = tsubject;
}

public String getTtopic() {
    return Ttopic;
}

public void setTtopic(String ttopic) {
    Ttopic = ttopic;
}

public String getTtdate() {
    return Ttdate;
}

public void setTtdate(String ttdate) {
    Ttdate = ttdate;
}
}

my MainActivity

       package com.sjsbhints.pdfmanager;

          import androidx.annotation.Nullable;
        import androidx.appcompat.app.AppCompatActivity;
          import androidx.recyclerview.widget.LinearLayoutManager;
        import androidx.recyclerview.widget.RecyclerView;

         import android.os.Bundle;

           import com.firebase.ui.database.FirebaseRecyclerOptions;
          import com.google.firebase.database.FirebaseDatabase;

   public class CircularAct extends AppCompatActivity {

RecyclerView recyclerView;
CAdapter cAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_circular2);

    recyclerView = findViewById(R.id.rv);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));



    FirebaseRecyclerOptions<Cmodel> options =
            new FirebaseRecyclerOptions.Builder<Cmodel>()
                    .setQuery(FirebaseDatabase.getInstance().getReference().child("CircularData"), Cmodel.class)
                    .build();

    cAdapter = new CAdapter(options);
    recyclerView.setAdapter(cAdapter);

}


@Override
protected void onStart() {
    super.onStart();
    cAdapter.startListening();
}

@Override
protected void onStop() {
    super.onStop();
    cAdapter.stopListening();
}
}

my mainactivity Xml

   <?xml version="1.0" encoding="utf-8"?>
      <androidx.constraintlayout.widget.ConstraintLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     tools:context=".CircularAct">

     <androidx.recyclerview.widget.RecyclerView
    android:id="@ id/rv"
    android:layout_width="599dp"
    android:layout_height="960dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
    </androidx.constraintlayout.widget.ConstraintLayout>

CodePudding user response:

Your CardView definitely matched the parent's width because it inherited the width of the RecyclerView since that's its parent.

Your RecyclerView, on the other hand, has a width of 599dp. The fixed size means that it will ignore the device's width. To match the device's width and height, set it to match_parent or use 0dp since you're using a constraint layout in your case.

<androidx.recyclerview.widget.RecyclerView
    android:id="@ id/rv"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
    </androidx.constraintlayout.widget.ConstraintLayout>
  • Related