Android 平台之间的 RecyclerView 间距差异
Android RecyclerView Spacing Differences between Platforms
预先披露,这是一个学校项目。
关于 RecyclerView 内的 CardView 列表,我 运行 遇到了一个让我有点困惑的布局问题,即卡片之间的间距在 5.0 上不存在,但它很好在 4.4。这里有两个截图来演示。
Android 4.4(在设备上,Galaxy S4)
Android 5.0.1(在设备上,Nexus 4)
我在5.x版本中可以看到卡片角,所以卡片在那里。我感觉这与 运行 宁 5.x 所需的某些 XML 属性有关,支持库会在 4.x 上自动伪造,但谷歌搜索失败了.这是相关的 XML:
片段布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.hinodesoftworks.kanagt.HiraganaListFragment">
<android.support.v7.widget.RecyclerView
android:id="@+id/hira_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
卡片布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
card_view:cardCornerRadius="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/kana_card_display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="46sp"
android:text="あ"/>
<TextView
android:id="@+id/kana_card_roma"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/kana_card_display"
android:layout_toEndOf="@id/kana_card_display"
android:text="a"
/>
<TextView
android:id="@+id/kana_card_info1_display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/kana_card_display"
android:layout_toEndOf="@id/kana_card_display"
android:layout_below="@id/kana_card_roma"
android:text="INFO 1"/>
<TextView
android:id="@+id/kana_card_info2_display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/kana_card_display"
android:layout_toEndOf="@id/kana_card_display"
android:layout_below="@id/kana_card_info1_display"
android:text="INFO 2"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/kana_card_info2_display">
<ImageView
android:id="@+id/kana_card_diagram"
android:layout_width="match_parent"
android:layout_height="100dp"
android:scaleType="fitStart"
android:adjustViewBounds="true"/>
</HorizontalScrollView>
</RelativeLayout>
</android.support.v7.widget.CardView>
我真的希望这是一个简单的 XML 修复的愚蠢错误;支持库版本运行良好让我对此充满希望。
如果您希望 5.0 上的填充遵循与以前平台相同的规则,请将此属性添加到 CardView
XML 元素
app:cardUseCompatPadding="true"
在 Lollipop 上,可以在视图边界外绘制阴影。在 Kitkat 和更低的额外 space 必须为阴影保留。这就是为什么在 Lollipop 上必须明确设置间距。
预先披露,这是一个学校项目。
关于 RecyclerView 内的 CardView 列表,我 运行 遇到了一个让我有点困惑的布局问题,即卡片之间的间距在 5.0 上不存在,但它很好在 4.4。这里有两个截图来演示。
Android 4.4(在设备上,Galaxy S4)
Android 5.0.1(在设备上,Nexus 4)
我在5.x版本中可以看到卡片角,所以卡片在那里。我感觉这与 运行 宁 5.x 所需的某些 XML 属性有关,支持库会在 4.x 上自动伪造,但谷歌搜索失败了.这是相关的 XML:
片段布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.hinodesoftworks.kanagt.HiraganaListFragment">
<android.support.v7.widget.RecyclerView
android:id="@+id/hira_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
卡片布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
card_view:cardCornerRadius="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/kana_card_display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="46sp"
android:text="あ"/>
<TextView
android:id="@+id/kana_card_roma"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/kana_card_display"
android:layout_toEndOf="@id/kana_card_display"
android:text="a"
/>
<TextView
android:id="@+id/kana_card_info1_display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/kana_card_display"
android:layout_toEndOf="@id/kana_card_display"
android:layout_below="@id/kana_card_roma"
android:text="INFO 1"/>
<TextView
android:id="@+id/kana_card_info2_display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/kana_card_display"
android:layout_toEndOf="@id/kana_card_display"
android:layout_below="@id/kana_card_info1_display"
android:text="INFO 2"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/kana_card_info2_display">
<ImageView
android:id="@+id/kana_card_diagram"
android:layout_width="match_parent"
android:layout_height="100dp"
android:scaleType="fitStart"
android:adjustViewBounds="true"/>
</HorizontalScrollView>
</RelativeLayout>
</android.support.v7.widget.CardView>
我真的希望这是一个简单的 XML 修复的愚蠢错误;支持库版本运行良好让我对此充满希望。
如果您希望 5.0 上的填充遵循与以前平台相同的规则,请将此属性添加到 CardView
XML 元素
app:cardUseCompatPadding="true"
在 Lollipop 上,可以在视图边界外绘制阴影。在 Kitkat 和更低的额外 space 必须为阴影保留。这就是为什么在 Lollipop 上必须明确设置间距。