-1

i would like to place items with in a listview side by side like masonry view. but i would also like to have a tile that spreads over the two columns. i have found a few projects in git but non have a tile which spreads over the two columns. I have made 4 different list items layouts in xml but i cant seem to make them go side by side on runtime, could any one help me? how do i tell a list item to be on the side of another item in runtime? thanks in advanced.

P.s what i want is more or less this

____________
|           |
|           |
|           |
____________

_____  ______
|    | |     |
|    | |     |
|    | |     |
_____  _______
Eliahu Horwitz
  • 489
  • 3
  • 17
  • Can you give some more information on your problem? In your 'drawing' I can see only 2 rows. How would the other rows be? Is it only the 1st row that consists of 1 item and all the other ones consist of 2? – Alex Styl Sep 03 '15 at 13:24
  • I would like to have two logical columns but in reality only one list view, the columns should have items on them which are either on on or on the other or on both(this is the reason i dont want to lists) – Eliahu Horwitz Sep 03 '15 at 13:31

3 Answers3

2

Use Recyclerview with gridlayoutmanager to accomplish side by side items. moreinfo about recyclerview Here

Akshay Bhat 'AB'
  • 2,567
  • 3
  • 16
  • 29
  • 1
    Got a notification about this post reaching 1000 views so ill share what ive done. Ended up writing my own staggered layout manager and inflating 2 different layouts – Eliahu Horwitz Apr 02 '17 at 10:34
2

you can do something like this

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Title"
        android:layout_margin="20dp"
        android:textSize="30sp"
        android:layout_gravity="center_horizontal"/>

    <LinearLayout
        android:layout_width="fill_parent"
        android:orientation="horizontal"
        android:layout_height="fill_parent">
        <ListView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_marginRight="5dp"
            android:layout_weight="1"/>
        <ListView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_marginLeft="5dp"

            android:layout_weight="1"/>
    </LinearLayout>

</LinearLayout>

This will give you this enter image description here

Tomer Shemesh
  • 4,740
  • 1
  • 20
  • 39
0

You cannot do that with ListView.

You can either change the ListView to GridView and keep the adapter, or migrate to the new view RecyclerView .

I'd strongly suggest you choose the later, even if it looks a bit more work until you get used to, but you get all sorts of cool stuff from it for free, such as Item Decorators, or change the way the items are rendered (Vertically or Horizontally) or make different row have different amount of children and so on.

Alex Styl
  • 3,284
  • 2
  • 25
  • 42
  • does it have support for old api versions? – Eliahu Horwitz Sep 03 '15 at 13:15
  • I am afraid it doesn't. RecyclerView is really flexible compared to ListView and they changed they implementation dramatically. – Alex Styl Sep 03 '15 at 13:16
  • Sorry, misread your question. Check the link of the RecyclerView I linked. At the very end, it contains information on including it to your project. It is API level 7+ [compile 'com.android.support:recyclerview-v7:21.0.+'] – Alex Styl Sep 03 '15 at 22:16
  • That is something I could never properly understand, the dependency format. V7 means api 7+? Or that it is version 7 of build libraries ? Or 21.0+ mean it's api 21 +? Like is it compatible with ics kitkat and higher or is it lollipop and higher? – Eliahu Horwitz Sep 03 '15 at 23:22
  • It means that it supports api levels 7 and up. The 21.0 is the version of the library you would like to include. It is a bit confusing until you get used to it, that's for sure. – Alex Styl Sep 05 '15 at 00:28