I currently have a ListView set up that is populated with JSON data from my website. I want to add a layout above the ListView, but still make it scrollable with the ListView.
Here is my current ListView layout (listview_layout.xml
):
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="0dp"
android:divider="@null" />
</LinearLayout>
Here is the onCreateView()
method from the fragment that loads the JSON data into the adapter and then into the ListView:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.listview_layout, container, false);
final ListView listView = (ListView) view.findViewById(R.id.listview);
final ArrayList<User> userArray = new ArrayList<User>();
final RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(URL).build();
final ApiEndpointInterface apiService = restAdapter.create(ApiEndpointInterface.class);
apiService.getUsers(new Callback<UserData>() {
@Override
public void success(UserData userData, Response response) {
final UserAdapter adapter = new UserAdapter(getActivity(), userArray);
userArray.addAll(userData.getData());
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
@Override
public void failure(RetrofitError retrofitError) {
retrofitError.printStackTrace();
}
});
return view;
}
Here is the layout I want to above the ListView:
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="30dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/ic_user"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User"
android:textSize="18sp"
android:layout_gravity="center_vertical" />
</LinearLayout>
How can I add this layout above the ListView and have it scroll with the ListView (not a sticky/fixed layout)?
To illustrate, here is what I need. Notice the scrollbar (red) is over the whole screen, not just the ListView: