Android Material 带有 HorizontalScrollView 的 CardView
Android Material CardView with HorizontalScrollView
我需要像下面的教程一样在 HorizontalScrollView
中显示 CardViews
http://examples.javacodegeeks.com/android/core/ui/horizontalscrollview/android-horizontalscrollview-example/
这是我尝试过的:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3">
<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:id="@+id/view2"
android:layout_width="170dp"
android:layout_height="220dp"
android:layout_alignParentEnd="true"
android:layout_alignTop="@+id/horizontalScrollView"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="3dp"
card_view:cardElevation="3sp"
card_view:cardUseCompatPadding="true" />
</RelativeLayout>
</HorizontalScrollView>
<android.support.v7.widget.CardView
android:id="@+id/view5"
android:layout_width="170dp"
android:layout_height="220dp"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="3dp"
card_view:cardElevation="3sp"
card_view:cardUseCompatPadding="true"
android:layout_alignTop="@+id/horizontalScrollView"
android:layout_alignParentEnd="true"
android:layout_marginEnd="33dp" />
</RelativeLayout>
但我不能在此布局中使用两个以上的卡片视图。(inHorizontalScrollView
)
我应该为这个 porpose 使用另一个小部件吗?或者如果我需要在这个 Horizontal ScrollView 中显示 5 个 CardView 会有什么问题?
干杯!
您可以使用 RecyclerView which comes in the android support library and u can see how to add it to your project here。这是一个更好的列表视图实现,它带有一个布局管理器,您可以通过它配置它以用作 Horizontal
或 vertical
滚动模式 .
mRecyclerLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
我需要像下面的教程一样在 HorizontalScrollView
中显示 CardViews
http://examples.javacodegeeks.com/android/core/ui/horizontalscrollview/android-horizontalscrollview-example/
这是我尝试过的:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3">
<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:id="@+id/view2"
android:layout_width="170dp"
android:layout_height="220dp"
android:layout_alignParentEnd="true"
android:layout_alignTop="@+id/horizontalScrollView"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="3dp"
card_view:cardElevation="3sp"
card_view:cardUseCompatPadding="true" />
</RelativeLayout>
</HorizontalScrollView>
<android.support.v7.widget.CardView
android:id="@+id/view5"
android:layout_width="170dp"
android:layout_height="220dp"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="3dp"
card_view:cardElevation="3sp"
card_view:cardUseCompatPadding="true"
android:layout_alignTop="@+id/horizontalScrollView"
android:layout_alignParentEnd="true"
android:layout_marginEnd="33dp" />
</RelativeLayout>
但我不能在此布局中使用两个以上的卡片视图。(inHorizontalScrollView
)
我应该为这个 porpose 使用另一个小部件吗?或者如果我需要在这个 Horizontal ScrollView 中显示 5 个 CardView 会有什么问题?
干杯!
您可以使用 RecyclerView which comes in the android support library and u can see how to add it to your project here。这是一个更好的列表视图实现,它带有一个布局管理器,您可以通过它配置它以用作 Horizontal
或 vertical
滚动模式 .
mRecyclerLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);