emen
emen

Reputation: 6308

Android Layout - Making scrollable layout

I have a ListView and an ImageView contained in a LinearLayout. Unfortunately, ListView doesn't scroll the ImageView together with it.

I've tried to use ScrollView to wrap both components, but there is a problem with ListView if I did so.

Anyone know how to make all of the components inside LinearLayout scroll?

Here is my layout xml:

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

    <ImageView
        android:id="@+id/imgCanvas"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:scaleType="centerCrop" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/imgCanvas"
        android:smoothScrollbar="true" />
</LinearLayout>

Here is the screenshot of how it looks right now:

scrollview and listview

Upvotes: 0

Views: 82

Answers (2)

Roman Black
Roman Black

Reputation: 3497

You can make your ImageView in another layout file, inflate it and add as HeaderView.

For example:

View header = LayoutInflater.from(this).inflate(R.layout.your_imageview_layout, null);
yourListView.addHeader(header, null, false);

Upvotes: 3

Damien R.
Damien R.

Reputation: 3373

You should try to set your image as header of your list.

Use the following function to do this:

yourListView.addHeaderView(yourImageView, null, false);

Upvotes: 1

Related Questions