@abukhvalov
Бездарность. Хуже Петросяна.

Android. Разбить контент на два столбца?

P1rwN.png

Возможно ли получить такой результат без использования ListView, RecyclerView и т.д.

Сейчас у меня делается так:
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);
  • Вопрос задан
  • 1644 просмотра
Пригласить эксперта
Ответы на вопрос 3
anyd3v
@anyd3v
у CardView android:numColumns="2" пробовали?
Ответ написан
buksttabu
@buksttabu
А если 2 linear'a с равными весами?
Ответ написан
konstantin_berkow
@konstantin_berkow
Начинающий разработчик
Если не хотите использовать RecyclerView и GridView, можете воспользоваться GridLayout с двумя колонками, но я подозреваю что вы хотите два независимых скролящихся списка. Но насколько я понял контент у вас ограничен, а даже если и нет и вы не хотите использовать потомков AdapterView/ RecyclerView, можете воспользоваться таким 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>


И можете как раньше добавлять в start_container_layout и end_container_layout ваши вьюшки. Но лучше всё-таки использовать потомка AdapterView или RecyclerView.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы