0

I'm filling in my Recycler View with the data of all the records from my SQLite DB (one record under another). I need to scroll the Recycler View horizontal, because some words are larger and don't enter into the screen, like you can see in the image below:

enter image description here

This is my RecyclerView Layout, but still not working:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <EditText
        android:id="@+id/etIngresar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Ingrese un verbo"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.08"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.023" />

    <Button
        android:id="@+id/bnMostrar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="mostrar"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.822"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.019" />
</android.support.constraint.ConstraintLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/rvListItems"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="70dp"
    android:layout_marginRight="20dp"
    android:layout_marginBottom="70dp"
    android:scrollbarSize="4dp"
    android:scrollbars="horizontal"
    android:orientation="horizontal" />

</RelativeLayout>

I can't set this in my Activity because it converts the scrolling horizontal BUT it put all the records in one line, and I don't want it.

    LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL,true);

Like this:

enter image description here

EDITED

My Recycler View class:

public class RecyclerViewAdapter extends RecyclerView.Adapter {
private ArrayList<Items> listItem ;

public RecyclerViewAdapter(ArrayList<Items> listItem) {
    this.listItem = listItem;
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View contentView = LayoutInflater.from(parent.getContext()).inflate(R.layout.lista, null);
    System.out.println("CREATE VIEW HOLDER: " + viewType);
    return new Holder(contentView);
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    Items item = listItem.get(position);
    Holder Holder = (Holder) holder;
    Holder.tvVerbo.setText(item.getVerbo());
    Holder.tvReferencia.setText(item.getReferencia());
    Holder.tvEu.setText(item.getEu());
    Holder.tvVoce.setText(item.getVoce());
    Holder.tvNos.setText(item.getNos());
    Holder.tvVoces.setText(item.getVoces());

    System.out.println("BIND VIEW HOLDER: " + position);
}

@Override
public int getItemCount() {
    return listItem.size();
}

public class Holder extends RecyclerView.ViewHolder{
    TextView tvVerbo;
    TextView tvReferencia;
    TextView tvEu;
    TextView tvVoce;
    TextView tvNos;
    TextView tvVoces;

    public Holder(View itemView) {
        super(itemView);
        tvVerbo = itemView.findViewById(R.id.tvLista1);
        tvReferencia = itemView.findViewById(R.id.tvLista2);
        tvEu = itemView.findViewById(R.id.tvLista3);
        tvVoce = itemView.findViewById(R.id.tvLista4);
        tvNos = itemView.findViewById(R.id.tvLista5);
        tvVoces = itemView.findViewById(R.id.tvLista6);

    }
}
}

My activity Verbos2 when I call the Recycler:

public class Verbos2 extends AppCompatActivity {

RecyclerView recyclerViewItem;
RecyclerViewAdapter recyclerViewVerbos;
EditText etVerbos;
Button mostrar;

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

    etVerbos = findViewById(R.id.etIngresar);
    mostrar = findViewById(R.id.bnMostrar);

    recyclerViewItem = findViewById(R.id.rvListItems);
    LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL,false);
    recyclerViewItem.setLayoutManager(manager);

    mostrar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            List<Items> completeList = new ArrayList<>();
            completeList.addAll(mostrarVerbos());
            recyclerViewVerbos = new RecyclerViewAdapter((ArrayList<Items>) completeList);
            recyclerViewItem.setAdapter(recyclerViewVerbos);
        }
    });
}

public List<Items> mostrarVerbos(){
    BaseDeDatos admin = new BaseDeDatos(getApplicationContext(), "verbos.db", getApplicationContext(), 11);
    SQLiteDatabase db = admin.getReadableDatabase();
    String[] parametros = {etVerbos.getText().toString()};
    Cursor cursor = db.rawQuery("SELECT * FROM verbos WHERE verbos =?", parametros);
    List<Items> verbos= new ArrayList<>();
    if(cursor.moveToFirst()){
        do {
            verbos.add(new Items(cursor.getString(1), " " + cursor.getString(2), " " + cursor.getString(3), " " + cursor.getString(4), " " + cursor.getString(5), " " + cursor.getString(6)));
        }while (cursor.moveToNext());
    }else{
        Toast.makeText(getApplicationContext(), "El verbo no existe", Toast.LENGTH_LONG).show();
    }
    return verbos;
}
}

The list xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:andoid="http://schemas.android.com/apk/res-auto">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/tvLista1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="algo1"
        android:textSize="15sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/tvLista2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="algo 2"
        android:textSize="15sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/tvLista3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="algo 3"
        android:textSize="15sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/tvLista4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="algo 4"
        android:textSize="15sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/tvLista5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="algo 5"
        android:textSize="15sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/tvLista6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="algo 5"
        android:textSize="15sp"
        android:textStyle="bold" />

</LinearLayout>

</LinearLayout>

EDITED 2

Ass you can see, it generated an horizontally scroll to each record. I need just one horizontally scroll that envolves all the records at the same time (3 records in this case)

enter image description here

1
  • Please paste xml of Recyclerview adapter class. Commented Jan 24, 2020 at 7:31

2 Answers 2

0

Try to add horizontal scroll view inside of your item layout and set maxLines 1 into your item textView.

Try below code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:overScrollMode="never">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:id="@+id/tvLista1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="algo1"
                android:maxLines="1"
                android:textSize="15sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/tvLista2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="algo 2"
                android:maxLines="1"
                android:textSize="15sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/tvLista3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="algo 3"
                android:maxLines="1"
                android:textSize="15sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/tvLista4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="algo 4"
                android:maxLines="1"
                android:textSize="15sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/tvLista5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="algo 5"
                android:maxLines="1"
                android:textSize="15sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/tvLista6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="algo 5"
                android:maxLines="1"
                android:textSize="15sp"
                android:textStyle="bold" />
        </LinearLayout>
    </HorizontalScrollView>
</LinearLayout>

I hope this can help You!

Thank You.

Sign up to request clarification or add additional context in comments.

15 Comments

that almost worked! because it added the horizontal scrolling only to the larger record (the second one) but not to the another two records. I need the same but scrolling all the records horizontally at the same time, not only some of them
What you want?scroll horizontally or vertically?
Are you want If record was large then it scroll to horizontal or else scroll vertically?
I want to scroll only horizontally, all the records at the same time (3 in this case). With your method, it scroll only one record, I mean, it generated a horizontally scroll to each record. I need an universal horizontally scrolling to all records at the same time, not one scrolling per each record
Can you share screen shot for what problem generated?
|
0

i don't The problem is originating from your recyclerview. You have to set multiline to true on the TextView inside the recyclerview's layout item so that the text can span multiple lines.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.