5

新しいウィジェット CardView 内に ListView を実装しようとしています。Google で検索したときに、Chrome と同じ結果を得たいと考えています。私が何を意味するかを知らせるために画面を投稿します。 画面

ご覧のとおり、カードは 2 枚あります。検索結果は 2 番目のカードに表示され、スクロールバーはカード内ではなく外側にあります。私の実装では、代わりにスクロールバーがカード内にあるため、ListView アイテムはカード内でスクロールします!

私は自分のコードを投稿します:

xml レイアウト (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:

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;
    }
}

画面で同じ結果を出すための提案はありますか? 前もって感謝します!

4

0 に答える 0