0

I am trying to figure out how to setup a layout like this:

Layout

Basically I want to achieve that as the user scrolls he scrolls over whole layout not only in listview, which should consist of comments. As far as I know including ListView inside ScrollView is not recommended. Also maybe in future I would like to include MapView or MapFragment between ListView and some text. So how can I achieve this kind of layout ?

Carl Anderson
  • 3,446
  • 1
  • 25
  • 45
Lubos Mudrak
  • 651
  • 1
  • 8
  • 26

2 Answers2

0

According to Guy Romain (one of Android's key developers), the answer is to use a LinearLayout instead of a Listview. You can see his reasoning here.

Community
  • 1
  • 1
Carl Anderson
  • 3,446
  • 1
  • 25
  • 45
0

You can add only a ListView, and put the "title" and "some text" in a Header. Here is how you can implement it: For the header, you should create a layout: for example called header:`

            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="title"
               />

            <TextView
                android:id="@+id/some_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="some text"
               />
        </LinearLayout>

`

and in your activity you should declare the header: LayoutInflater inflater = LayoutInflater.from(this); View header = inflater.inflate(R.layout.header, null);

and:

ListView yourListView;
 yourListView.addHeaderView(carouselBlock);

and you should be carefull to add the header before setting the adapter of the list.

Houssem
  • 36
  • 2