how can I make a horizontal ListView on android?

2

They could tell me how I can do a Horizontal ListView, I have a HorizontalScrollView but it gets stuck when I use it, but I have no idea how to do the Horizontal ListView.

Thanks in advance.

    
asked by Erick Raul Marquez 01.08.2016 в 22:30
source

1 answer

4

On the internet there are many tutorials such as "How to do ListView Horizontals" , but I recommend you even more to use RecyclerView to have a better performance, this is a example :

public class MyActivity extends Activity {

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

        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);

        MyAdapter adapter = new MyAdapter(myDataset);
        recyclerView.setAdapter(adapter);
    }
}

this is the my_recycler_view.xml layout

<android.support.v7.widget.RecyclerView
    android:id="@+id/my_recycler_view"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

In relation to your question of how to add buttons ?, within your onCreateViewHolder() method of the Adapter that extends RecyclerView.Adapter you can create a view that contains buttons:

@Override
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
                                               int viewType) {
    // create a new view
    View v = LayoutInflater.from(parent.getContext())
                           .inflate(R.layout.mi_vista_con_botones, parent, false);
    // set the view's size, margins, paddings and layout parameters
    ...
    ViewHolder vh = new ViewHolder(v);
    return vh;
}

You would create something similar to:

    
answered by 01.08.2016 / 23:30
source