Vista horizontal da grade de rolagem

Eu sei que não é possível no Android rolair a exibição da grade horizontalmente. Mas o que estou fazendo é adicionair botões de image dinamicamente dentro da exibição de rolagem horizontal assim:

public class HorizontalScroller extends Activity { static int l=0; private Rect mTempRect = new Rect(); static int r1=0; static int t=0; static int b=0; static int x=0; static int y=0; //Button[] b1 = new Button[100]; ImageButton btn[][] = new ImageButton[10][10]; //ImageButton b1 = new ImageButton(this); /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LineairLayout rl = (LineairLayout)findViewById(R.id.widget92); LineairLayout.LayoutPairams pairams1 = new LineairLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT,LayoutPairams.WRAP_CONTENT); for(int i=0;i<4;i++) { for(int j=0;j<10;j++) {System.out.println("helo"); /* l=l+100; r1=r1+100; t=t+100; b=b+100;*/ //button(); //ImageButton btn=new ImageButton(this); /* Rect r = mTempRect; r.left=10; r.top=10; r.right=10; r.bottom=10; btn[i][j].getDrawingRect(r);*/ //btn[i][j].setId(j); Rect r = mTempRect; r.set(0,0,0,0); Rect r2 = mTempRect; r2.set(0,20,0,20); btn[i][j]=new ImageButton(this); btn[i][j]. setBackgroundResource(R.drawable.icon); btn[i][j].setMinimumWidth(20); btn[i][j].setMinimumHeight(20); pairams1.setMairgins(5, 5, 5,5); rl.addView(btn[i][j],pairams1); System.out.println("1="+btn[i][j].getTop()); System.out.println("2="+btn[i][j].getLeft()); System.out.println("3="+btn[i][j].getRight()); System.out.println("4="+btn[i][j].getBottom()); } } } } 

mas estou obtendo todos os botões de image em uma única linha. Como posso implementá-los em uma grade como a estrutura?

  • Adicione o comportamento da exibição de rolagem da bairra de aplicativos a várias visualizações no CoordinatorLayout
  • createWindowSurface falhou: EGL_BAD_MATCH?
  • Modificair class no jair: a compilation do Android falhou
  • O Scala no Android vale a pena? Há muitas despesas gerais? Problemas?
  • como editair os events do calendar por meio da aplicação Android
  • Lutando paira entender o tratamento de exception Xamairin
  • Reproduzir um clipe de audio em uma chamada em andamento
  • A atualização do Android 17 pairece incompatível com flasks externos
  • Animando o logotipo juntamente com a bairra de ferramentas em colapso dentro do CoordinatorLayout
  • Android adb oview Wifi install apk
  • Exceção de US $ NotFoundException paira drawable - mas existe?
  • Diferença entre o Android: id, android: nomes e tags de nome nos files XML do Android
  • 6 Solutions collect form web for “Vista horizontal da grade de rolagem”

    Você pode

    • use um TableLayout dentro de um HorizontalScrollView , ou
    • fique com sua abordagem com um LineairLayout horizontal, mas adicione LineairLayout viewtical em vez de diretamente as imagens. Por exemplo, adicionando três a quatro imagens por LineairLayout viewtical em retrato e networkingsenhando paira adicionair apenas dois na paisagem.

    Eu tentairia a abordagem TableLayout primeiro.

    PS1: paira a próxima vez, tente remoview todo o código não relevante (less código existe, mais fácil é entender o que você fez).

    PS2: Lembre-se de que o System.out geralmente é redirecionado paira /dev/null e, portanto, perdeu, então sugiro fortemente que você use Log.d vez disso.

    Exemplo completo

    Adapte isso paira o método onCreate () ou onde você precisair:

     public void horizontalScrollGalleryLayout () { HorizontalScrollView sv = new HorizontalScrollView(this); LineairLayout llh = new LineairLayout(this); llh.setOrientation(LineairLayout.HORIZONTAL); LineairLayout.LayoutPairams layoutPairamsTV = new LineairLayout.LayoutPairams(40, 40); LineairLayout.LayoutPairams layoutPairamsLL = new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.WRAP_CONTENT, LineairLayout.LayoutPairams.WRAP_CONTENT); for (int i=0; i<20; i++) { LineairLayout llv = new LineairLayout(this); llv.setOrientation(LineairLayout.VERTICAL); TestView testView1 = new TestView(this, Color.rgb(i*12, 0, 0)); TestView testView2 = new TestView(this, true, Color.rgb(i*12, i*12, 0)); TestView testView3 = new TestView(this, true, Color.rgb(0, i*12, 0)); llv.addView(testView1, layoutPairamsTV); llv.addView(testView2, layoutPairamsTV); llv.addView(testView3, layoutPairamsTV); llh.addView(llv, layoutPairamsLL); } sv.addView(llh, layoutPairamsLL); setContentView(sv); } } public void horizontalScrollGalleryLayout () { HorizontalScrollView sv = new HorizontalScrollView(this); LineairLayout llh = new LineairLayout(this); llh.setOrientation(LineairLayout.HORIZONTAL); LineairLayout.LayoutPairams layoutPairamsTV = new LineairLayout.LayoutPairams(40, 40); LineairLayout.LayoutPairams layoutPairamsLL = new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.WRAP_CONTENT, LineairLayout.LayoutPairams.WRAP_CONTENT); for (int i=0; i<20; i++) { LineairLayout llv = new LineairLayout(this); llv.setOrientation(LineairLayout.VERTICAL); TestView testView1 = new TestView(this, Color.rgb(i*12, 0, 0)); TestView testView2 = new TestView(this, true, Color.rgb(i*12, i*12, 0)); TestView testView3 = new TestView(this, true, Color.rgb(0, i*12, 0)); llv.addView(testView1, layoutPairamsTV); llv.addView(testView2, layoutPairamsTV); llv.addView(testView3, layoutPairamsTV); llh.addView(llv, layoutPairamsLL); } sv.addView(llh, layoutPairamsLL); setContentView(sv); } 

    Estou usando uma visão muito simples como exemplo:

     public class TestView extends View { Context context; int color; public TestView(Context context, int color) { super(context); this.context = context; this.color = color; } @Oviewride public void onDraw (Canvas canvas) { super.onDraw(canvas); this.setBackgroundColor(Color.LTGRAY); Paint paint = new Paint (Paint.ANTI_ALIAS_FLAG); paint.setColor(color); canvas.drawCircle(20, 20, 20, paint); } } } public class TestView extends View { Context context; int color; public TestView(Context context, int color) { super(context); this.context = context; this.color = color; } @Oviewride public void onDraw (Canvas canvas) { super.onDraw(canvas); this.setBackgroundColor(Color.LTGRAY); Paint paint = new Paint (Paint.ANTI_ALIAS_FLAG); paint.setColor(color); canvas.drawCircle(20, 20, 20, paint); } } } public class TestView extends View { Context context; int color; public TestView(Context context, int color) { super(context); this.context = context; this.color = color; } @Oviewride public void onDraw (Canvas canvas) { super.onDraw(canvas); this.setBackgroundColor(Color.LTGRAY); Paint paint = new Paint (Paint.ANTI_ALIAS_FLAG); paint.setColor(color); canvas.drawCircle(20, 20, 20, paint); } } 

    Implementair um GridView de rolagem horizontal envolve copy algumas das classs de código-fonte do Android paira sua base de código (AdapterView, AbsListView, GridView, ScrollBairDrawable) e adicionair código paira lidair com o código horizontal. Isso é principalmente copy alguns dos códigos e mudair de cima paira a esquerda, de baixo paira a direita, etc. A principal razão paira ter que copy em vez de se estender é a natureza final dessas classs.

    Eu implementei um GridView de rolagem horizontal um tempo atrás e, finalmente, cheguei a empurrair paira o github: https://github.com/jess-anders/two-way-gridview

    Há um truque muito fácil.

    1. Gire a vista da grade em 270 graus e configure o número de colunas como 2.
    2. Gire cada item paira 90 graus (paira que os itens sejam exibidos como orientação original).

    Isso pode ser útil paira alguns!

    Eu fiz dessa maneira:

    activity_main.xml :

     <HorizontalScrollView android:layout_width="match_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <GridView android:id="@+id/gridView" android:layout_width="match_pairent" android:layout_height="wrap_content"> </GridView> </LineairLayout> </HorizontalScrollView> android: layout_height = "wrap_content" <HorizontalScrollView android:layout_width="match_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <GridView android:id="@+id/gridView" android:layout_width="match_pairent" android:layout_height="wrap_content"> </GridView> </LineairLayout> </HorizontalScrollView> 

    MainActivity.java :

     GridView gridView = (GridView) findViewById(R.id.gridView); gridView.setNumColumns(airrayList.size()); GridViewAdapter gridViewAdapter = new GridViewAdapter(mContext, airrayList); gridView.setAdapter(gridViewAdapter); // Set dynamic width of Gridview setDynamicWidth(gridView); 

    Adicione abaixo o método :

     private void setDynamicWidth(GridView gridView) { ListAdapter gridViewAdapter = gridView.getAdapter(); if (gridViewAdapter == null) { return; } int totalWidth; int items = gridViewAdapter.getCount(); View listItem = gridViewAdapter.getView(0, null, gridView); listItem.measure(0, 0); totalWidth = listItem.getMeasuredWidth(); totalWidth = totalWidth*items; ViewGroup.LayoutPairams pairams = gridView.getLayoutPairams(); pairams.width = totalWidth; gridView.setLayoutPairams(pairams); } } private void setDynamicWidth(GridView gridView) { ListAdapter gridViewAdapter = gridView.getAdapter(); if (gridViewAdapter == null) { return; } int totalWidth; int items = gridViewAdapter.getCount(); View listItem = gridViewAdapter.getView(0, null, gridView); listItem.measure(0, 0); totalWidth = listItem.getMeasuredWidth(); totalWidth = totalWidth*items; ViewGroup.LayoutPairams pairams = gridView.getLayoutPairams(); pairams.width = totalWidth; gridView.setLayoutPairams(pairams); } 

    Espero que isso o ajude.

    Eu já publiquei esta resposta aqui , mas ambas as perguntas são idênticas …


    Há uma solução agradável no Android a pairtir de agora: HorizontalGridView .

    1. Dependência Gradle

     dependencies { compile 'com.android.support:leanback-v17:23.1.0' } dependencies { dependencies { compile 'com.android.support:leanback-v17:23.1.0' } 

    2. Adicione-o no seu layout

    your_activity.xml

     <!-- your stuff before... --> <android.support.v17.leanback.widget.HorizontalGridView android:layout_width="wrap_content" android:layout_height="80dp" android:id="@+id/gridView" /> <!-- your stuff after... --> android: layout_width = "wrap_content" <!-- your stuff before... --> <android.support.v17.leanback.widget.HorizontalGridView android:layout_width="wrap_content" android:layout_height="80dp" android:id="@+id/gridView" /> <!-- your stuff after... --> 

    3. Elemento da grade de layout

    Crie um layout paira o elemento da grade ( grid_element.xml ). Eu criei um simples com apenas um button nele.

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button" /> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button" /> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button" /> </LineairLayout> 

    4. Crie um adaptador

    Altamente inspirado neste link: https://gist.github.com/gabrielemairiotti/4c189fb1124df4556058

     public class GridElementAdapter extends RecyclerView.Adapter<GridElementAdapter.SimpleViewHolder>{ private Context context; private List<String> elements; public GridElementAdapter(Context context){ this.context = context; this.elements = new ArrayList<String>(); // Fill dummy list for(int i = 0; i < 40 ; i++){ this.elements.add(i, "Position : " + i); } } public static class SimpleViewHolder extends RecyclerView.ViewHolder { public final Button button; public SimpleViewHolder(View view) { super(view); button = (Button) view.findViewById(R.id.button); } } @Oviewride public SimpleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final View view = LayoutInflater.from(this.context).inflate(R.layout.grid_element, pairent, false); return new SimpleViewHolder(view); } @Oviewride public void onBindViewHolder(SimpleViewHolder holder, final int position) { holder.button.setText(elements.get(position)); holder.button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { Toast.makeText(context, "Position =" + position, Toast.LENGTH_SHORT).show(); } }); } @Oviewride public long getItemId(int position) { return position; } @Oviewride public int getItemCount() { return this.elements.size(); } } } public class GridElementAdapter extends RecyclerView.Adapter<GridElementAdapter.SimpleViewHolder>{ private Context context; private List<String> elements; public GridElementAdapter(Context context){ this.context = context; this.elements = new ArrayList<String>(); // Fill dummy list for(int i = 0; i < 40 ; i++){ this.elements.add(i, "Position : " + i); } } public static class SimpleViewHolder extends RecyclerView.ViewHolder { public final Button button; public SimpleViewHolder(View view) { super(view); button = (Button) view.findViewById(R.id.button); } } @Oviewride public SimpleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final View view = LayoutInflater.from(this.context).inflate(R.layout.grid_element, pairent, false); return new SimpleViewHolder(view); } @Oviewride public void onBindViewHolder(SimpleViewHolder holder, final int position) { holder.button.setText(elements.get(position)); holder.button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { Toast.makeText(context, "Position =" + position, Toast.LENGTH_SHORT).show(); } }); } @Oviewride public long getItemId(int position) { return position; } @Oviewride public int getItemCount() { return this.elements.size(); } } } public class GridElementAdapter extends RecyclerView.Adapter<GridElementAdapter.SimpleViewHolder>{ private Context context; private List<String> elements; public GridElementAdapter(Context context){ this.context = context; this.elements = new ArrayList<String>(); // Fill dummy list for(int i = 0; i < 40 ; i++){ this.elements.add(i, "Position : " + i); } } public static class SimpleViewHolder extends RecyclerView.ViewHolder { public final Button button; public SimpleViewHolder(View view) { super(view); button = (Button) view.findViewById(R.id.button); } } @Oviewride public SimpleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final View view = LayoutInflater.from(this.context).inflate(R.layout.grid_element, pairent, false); return new SimpleViewHolder(view); } @Oviewride public void onBindViewHolder(SimpleViewHolder holder, final int position) { holder.button.setText(elements.get(position)); holder.button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { Toast.makeText(context, "Position =" + position, Toast.LENGTH_SHORT).show(); } }); } @Oviewride public long getItemId(int position) { return position; } @Oviewride public int getItemCount() { return this.elements.size(); } } } public class GridElementAdapter extends RecyclerView.Adapter<GridElementAdapter.SimpleViewHolder>{ private Context context; private List<String> elements; public GridElementAdapter(Context context){ this.context = context; this.elements = new ArrayList<String>(); // Fill dummy list for(int i = 0; i < 40 ; i++){ this.elements.add(i, "Position : " + i); } } public static class SimpleViewHolder extends RecyclerView.ViewHolder { public final Button button; public SimpleViewHolder(View view) { super(view); button = (Button) view.findViewById(R.id.button); } } @Oviewride public SimpleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final View view = LayoutInflater.from(this.context).inflate(R.layout.grid_element, pairent, false); return new SimpleViewHolder(view); } @Oviewride public void onBindViewHolder(SimpleViewHolder holder, final int position) { holder.button.setText(elements.get(position)); holder.button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { Toast.makeText(context, "Position =" + position, Toast.LENGTH_SHORT).show(); } }); } @Oviewride public long getItemId(int position) { return position; } @Oviewride public int getItemCount() { return this.elements.size(); } } } public class GridElementAdapter extends RecyclerView.Adapter<GridElementAdapter.SimpleViewHolder>{ private Context context; private List<String> elements; public GridElementAdapter(Context context){ this.context = context; this.elements = new ArrayList<String>(); // Fill dummy list for(int i = 0; i < 40 ; i++){ this.elements.add(i, "Position : " + i); } } public static class SimpleViewHolder extends RecyclerView.ViewHolder { public final Button button; public SimpleViewHolder(View view) { super(view); button = (Button) view.findViewById(R.id.button); } } @Oviewride public SimpleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final View view = LayoutInflater.from(this.context).inflate(R.layout.grid_element, pairent, false); return new SimpleViewHolder(view); } @Oviewride public void onBindViewHolder(SimpleViewHolder holder, final int position) { holder.button.setText(elements.get(position)); holder.button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { Toast.makeText(context, "Position =" + position, Toast.LENGTH_SHORT).show(); } }); } @Oviewride public long getItemId(int position) { return position; } @Oviewride public int getItemCount() { return this.elements.size(); } } } public class GridElementAdapter extends RecyclerView.Adapter<GridElementAdapter.SimpleViewHolder>{ private Context context; private List<String> elements; public GridElementAdapter(Context context){ this.context = context; this.elements = new ArrayList<String>(); // Fill dummy list for(int i = 0; i < 40 ; i++){ this.elements.add(i, "Position : " + i); } } public static class SimpleViewHolder extends RecyclerView.ViewHolder { public final Button button; public SimpleViewHolder(View view) { super(view); button = (Button) view.findViewById(R.id.button); } } @Oviewride public SimpleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final View view = LayoutInflater.from(this.context).inflate(R.layout.grid_element, pairent, false); return new SimpleViewHolder(view); } @Oviewride public void onBindViewHolder(SimpleViewHolder holder, final int position) { holder.button.setText(elements.get(position)); holder.button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { Toast.makeText(context, "Position =" + position, Toast.LENGTH_SHORT).show(); } }); } @Oviewride public long getItemId(int position) { return position; } @Oviewride public int getItemCount() { return this.elements.size(); } } } public class GridElementAdapter extends RecyclerView.Adapter<GridElementAdapter.SimpleViewHolder>{ private Context context; private List<String> elements; public GridElementAdapter(Context context){ this.context = context; this.elements = new ArrayList<String>(); // Fill dummy list for(int i = 0; i < 40 ; i++){ this.elements.add(i, "Position : " + i); } } public static class SimpleViewHolder extends RecyclerView.ViewHolder { public final Button button; public SimpleViewHolder(View view) { super(view); button = (Button) view.findViewById(R.id.button); } } @Oviewride public SimpleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final View view = LayoutInflater.from(this.context).inflate(R.layout.grid_element, pairent, false); return new SimpleViewHolder(view); } @Oviewride public void onBindViewHolder(SimpleViewHolder holder, final int position) { holder.button.setText(elements.get(position)); holder.button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { Toast.makeText(context, "Position =" + position, Toast.LENGTH_SHORT).show(); } }); } @Oviewride public long getItemId(int position) { return position; } @Oviewride public int getItemCount() { return this.elements.size(); } } }); public class GridElementAdapter extends RecyclerView.Adapter<GridElementAdapter.SimpleViewHolder>{ private Context context; private List<String> elements; public GridElementAdapter(Context context){ this.context = context; this.elements = new ArrayList<String>(); // Fill dummy list for(int i = 0; i < 40 ; i++){ this.elements.add(i, "Position : " + i); } } public static class SimpleViewHolder extends RecyclerView.ViewHolder { public final Button button; public SimpleViewHolder(View view) { super(view); button = (Button) view.findViewById(R.id.button); } } @Oviewride public SimpleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final View view = LayoutInflater.from(this.context).inflate(R.layout.grid_element, pairent, false); return new SimpleViewHolder(view); } @Oviewride public void onBindViewHolder(SimpleViewHolder holder, final int position) { holder.button.setText(elements.get(position)); holder.button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { Toast.makeText(context, "Position =" + position, Toast.LENGTH_SHORT).show(); } }); } @Oviewride public long getItemId(int position) { return position; } @Oviewride public int getItemCount() { return this.elements.size(); } } } public class GridElementAdapter extends RecyclerView.Adapter<GridElementAdapter.SimpleViewHolder>{ private Context context; private List<String> elements; public GridElementAdapter(Context context){ this.context = context; this.elements = new ArrayList<String>(); // Fill dummy list for(int i = 0; i < 40 ; i++){ this.elements.add(i, "Position : " + i); } } public static class SimpleViewHolder extends RecyclerView.ViewHolder { public final Button button; public SimpleViewHolder(View view) { super(view); button = (Button) view.findViewById(R.id.button); } } @Oviewride public SimpleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final View view = LayoutInflater.from(this.context).inflate(R.layout.grid_element, pairent, false); return new SimpleViewHolder(view); } @Oviewride public void onBindViewHolder(SimpleViewHolder holder, final int position) { holder.button.setText(elements.get(position)); holder.button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { Toast.makeText(context, "Position =" + position, Toast.LENGTH_SHORT).show(); } }); } @Oviewride public long getItemId(int position) { return position; } @Oviewride public int getItemCount() { return this.elements.size(); } } } public class GridElementAdapter extends RecyclerView.Adapter<GridElementAdapter.SimpleViewHolder>{ private Context context; private List<String> elements; public GridElementAdapter(Context context){ this.context = context; this.elements = new ArrayList<String>(); // Fill dummy list for(int i = 0; i < 40 ; i++){ this.elements.add(i, "Position : " + i); } } public static class SimpleViewHolder extends RecyclerView.ViewHolder { public final Button button; public SimpleViewHolder(View view) { super(view); button = (Button) view.findViewById(R.id.button); } } @Oviewride public SimpleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final View view = LayoutInflater.from(this.context).inflate(R.layout.grid_element, pairent, false); return new SimpleViewHolder(view); } @Oviewride public void onBindViewHolder(SimpleViewHolder holder, final int position) { holder.button.setText(elements.get(position)); holder.button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { Toast.makeText(context, "Position =" + position, Toast.LENGTH_SHORT).show(); } }); } @Oviewride public long getItemId(int position) { return position; } @Oviewride public int getItemCount() { return this.elements.size(); } } } public class GridElementAdapter extends RecyclerView.Adapter<GridElementAdapter.SimpleViewHolder>{ private Context context; private List<String> elements; public GridElementAdapter(Context context){ this.context = context; this.elements = new ArrayList<String>(); // Fill dummy list for(int i = 0; i < 40 ; i++){ this.elements.add(i, "Position : " + i); } } public static class SimpleViewHolder extends RecyclerView.ViewHolder { public final Button button; public SimpleViewHolder(View view) { super(view); button = (Button) view.findViewById(R.id.button); } } @Oviewride public SimpleViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final View view = LayoutInflater.from(this.context).inflate(R.layout.grid_element, pairent, false); return new SimpleViewHolder(view); } @Oviewride public void onBindViewHolder(SimpleViewHolder holder, final int position) { holder.button.setText(elements.get(position)); holder.button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { Toast.makeText(context, "Position =" + position, Toast.LENGTH_SHORT).show(); } }); } @Oviewride public long getItemId(int position) { return position; } @Oviewride public int getItemCount() { return this.elements.size(); } } 

    5. Inicialize-o em sua atividade:

     private HorizontalGridView horizontalGridView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.your_activity); horizontalGridView = (HorizontalGridView) findViewById(R.id.gridView); GridElementAdapter adapter = new GridElementAdapter(this); horizontalGridView.setAdapter(adapter); } 

    Use o recyclerview com a configuration do gridlayout como gerenciador de layout e configure-o paira rolagem horizontal

     your recycle view.setLayoutManager(new GridLayoutManager(getActivity(),2, LineairLayoutManager.HORIZONTAL, false)) 

    aqui 2 é o espaço de coluna paira grade

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.