0

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

0

2 Answers 2

3

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); 
Sign up to request clarification or add additional context in comments.

2 Comments

Do I have to use the same Adapter that populates the ListView one?
Yes, but your header will not appear before you set adapter
1

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

Use the following function to do this:

yourListView.addHeaderView(yourImageView, null, false); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.