5

我正在尝试在新的 Widget CardView 中实现 ListView。当我在 Google 上进行搜索时,我想获得与 Chrome 相同的结果。我给你贴一个屏幕让你知道我的意思。 屏幕

如您所见,有两张牌。搜索结果显示在第二张卡片中,滚动条不在卡片中,而是在卡片外面。相反,在我的实现中,滚动条在卡片内,因此 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