如何纠正 cardview-v7:27.0.2 的意外行为
How to correct unexpected behaviour of cardview-v7:27.0.2
将应用程序 SDK 23 升级到 27 后出现奇怪问题。这是我所期望的(卡片全宽);
这是我得到的(有些卡片不是全角)。滚动会导致卡片再次全宽!
相关代码在msgh_detail.xml
<include
android:layout_width="wrap_content"
android:layout_height="400dp"
layout="@layout/msgh_detail_list" />
相关代码在msgh_detail_list
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/detail_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
这是设置视图的代码
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.msgh_detail_list_item, parent, false);
view.setBackgroundResource(mBackground);
return new ViewHolder(view);
}
这里是实际布局的代码msgh_detail_list_item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="24dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_weight="0.97"
android:id="@+id/DayMMdd"
android:ellipsize="end"
android:maxLines="1"
android:hint="@string/day_mth_dte" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/arrivaltime"
android:layout_marginLeft="8dp"
android:hint="@string/Hour_min" />
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:id="@+id/avatar"
android:src="@drawable/status_1"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:longClickable="false" />
</LinearLayout>
<android.support.v7.widget.CardView
android:id="@+id/detail_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="#ccecf9">
<LinearLayout
style="@style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceListItem"
android:autoLink="web"
android:textColorLink="#009933"
android:layout_weight="0.97"
android:text="@string/test_msg" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
看起来很简单,之前也很好用。
可能是我的设置或层次结构有点不对..?
将activity布局中的wrap_content改为match_parent而不是wrap_content ..这就是问题所在...
将应用程序 SDK 23 升级到 27 后出现奇怪问题。这是我所期望的(卡片全宽);
这是我得到的(有些卡片不是全角)。滚动会导致卡片再次全宽!
相关代码在msgh_detail.xml
<include
android:layout_width="wrap_content"
android:layout_height="400dp"
layout="@layout/msgh_detail_list" />
相关代码在msgh_detail_list
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/detail_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
这是设置视图的代码
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.msgh_detail_list_item, parent, false);
view.setBackgroundResource(mBackground);
return new ViewHolder(view);
}
这里是实际布局的代码msgh_detail_list_item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="24dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_weight="0.97"
android:id="@+id/DayMMdd"
android:ellipsize="end"
android:maxLines="1"
android:hint="@string/day_mth_dte" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/arrivaltime"
android:layout_marginLeft="8dp"
android:hint="@string/Hour_min" />
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:id="@+id/avatar"
android:src="@drawable/status_1"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:longClickable="false" />
</LinearLayout>
<android.support.v7.widget.CardView
android:id="@+id/detail_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="#ccecf9">
<LinearLayout
style="@style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceListItem"
android:autoLink="web"
android:textColorLink="#009933"
android:layout_weight="0.97"
android:text="@string/test_msg" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
看起来很简单,之前也很好用。
可能是我的设置或层次结构有点不对..?
将activity布局中的wrap_content改为match_parent而不是wrap_content ..这就是问题所在...