-1

I implemented a listview in my layout:

<ListView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</ListView>

and then in my activity I set its adapter:

mListView = (ListView) findViewById(R.id.listView);
mListView.setAdapter(new MyAdapter(this, R.layout.list_item, mListImages));

MyAdapter handles the getView and displays the list vertically:

images1
images2
....

Can it display the list horizontally? this way:

image1  image2  ....

(for sure it should work with scroll and display all the images)

I saw that this result can be achieved with RecycleView and LayoutManager that gets Horizontal as a parameter but I have implemented the ListView already, which doesn't have the method "setLayoutManager". and I need it to work for API 15 and above.

Maor Cohen
  • 936
  • 2
  • 18
  • 33

2 Answers2

1

You could try with RecyclerView :

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);
}

}

and Layout as my_recycler_view.xml

<android.support.v7.widget.RecyclerView
    android:id="@+id/my_recycler_view"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
Willas
  • 63
  • 1
  • 10
0

Try with orientation

<ListView
    android:id="@+id/listView"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</ListView>
Zinc
  • 1,002
  • 12
  • 18