How to insert ListView into CardView with scroll bar outside CardView?

I am trying to implement a ListView inside a new CardView widget. I want to achieve the same result in Chrome when I search on Google. I am sending you a screen so you know what I mean. Screen

As you can see, there are two cards. Search results are displayed on the second map, and the scroll bar is not on the map, but outside. In my implementation, instead, the scrollbar is inside the map, so ListView items scroll inside the map!

I am sending my code:

xml layout (fragment_home.xml)

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

   <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view_search_2"
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        card_view:cardCornerRadius="4dp">

    <ListView 
        android:id="@+id/search_parameters_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </ListView>

    </android.support.v7.widget.CardView>

</LinearLayout>

JAVA fragment:

public class HomeFragment extends Fragment 
{

    private ListView mListView;

    private String[] stringValues;

    private SearchListItem searchItem;



    public HomeFragment(){}

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    {
        final View rootView = inflater.inflate(R.layout.fragment_home, container, false);

        mListView = (ListView) rootView.findViewById(R.id.search_parameters_list);

        stringValues = getResources().getStringArray(R.array.search_parameters);

        parameters = new ArrayList<SearchListItem>();


        for(int i = 0; i < stringValues.length; ++i)
        {
            parameters.add(new SearchListItem(stringValues[i], ""));
        }   

        ListViewSearchAdapter adapter = new ListViewSearchAdapter(getActivity(), parameters);

        mListView.setAdapter(adapter);


        return rootView;
    }
}

Any suggestion to do the same result on the screen? Thanks in advance!

+4

All Articles