A
A
abukhvalov2015-05-02 06:23:24
Android
abukhvalov, 2015-05-02 06:23:24

Android. Split content into two columns?

P1rwN.png
Is it possible to get such result without using ListView, RecyclerView etc.
Now I do it like this:
xml:

...

                <LinearLayout
                    android:id="@+id/cardContainer"
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true">
                    </LinearLayout>
...

one_list_item XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:background="#ffebebeb">

    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="15dp"
        android:layout_margin="15dp">
</android.support.v7.widget.CardView>
</LinearLayout>

java:
CardLayout = (LinearLayout) findViewById(R.id.cardContainer);
cell = getLayoutInflater().inflate(R.layout.one_list_item, null);
...
CardLayout.addView(cell);

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
anyd3v, 2015-05-02
@anyd3v

Have you tried CardView android:numColumns="2"?

B
buksttabu, 2015-05-02
@buksttabu

And if 2 linear'a with equal weights?

K
Konstantin Berkov, 2015-05-02
@konstantin_berkow

If you don't want to use RecyclerView and GridView, you can use GridLayout with two columns, but I suspect you want two independent scrolling lists. But as far as I understand, your content is limited, and even if not and you don’t want to use AdapterView / RecyclerView descendants, you can use this layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Space
        android:id="@+id/center_space"
        android:layout_centerInParent="true"
        android:layout_width="0dp"
        android:layout_height="0dp" />

    <ScrollView
        android:id="@+id/start_scroll_view"
        android:layout_toStartOf="@id/center_space"
        android:layout_alignParentStart="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <LinearLayout
            android:id="@+id/start_container_layout"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        
    </ScrollView>

    <ScrollView
        android:id="@+id/end_scroll_view"
        android:layout_toEndOf="@id/center_space"
        android:layout_alignParentEnd="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/end_container_layout"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        
    </ScrollView>
    
</RelativeLayout>

And you can add your views to start_container_layout and end_container_layout as before. But it's still better to use a descendant of AdapterView or RecyclerView.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question