我试图在新的Widget CardView中实现ListView。我想在Google上进行搜索时获得与Chrome相同的结果。我发布了一个屏幕让你知道我的意思。 Screen
如您所见,有两张牌。搜索结果显示在第二张卡片中,滚动条不在卡片中,但在外面。在我的实现中,相反,滚动条位于卡内,因此ListView项目在卡内滚动!
我发布了我的代码:
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>
Fragment 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;
}
}
是否有任何建议在屏幕上显示相同的结果?提前谢谢!