Android 如何纠正cardview-v7:27.0.2的意外行为
将app SDK 23升级到27后出现了奇怪的问题。这就是我所期望的(卡片全宽) 这是我得到的(有些牌不是全宽的)。滚动会使卡片再次变为全宽 msgh_detail.xml中的相关代码Android 如何纠正cardview-v7:27.0.2的意外行为,android,android-cardview,Android,Android Cardview,将app SDK 23升级到27后出现了奇怪的问题。这就是我所期望的(卡片全宽) 这是我得到的(有些牌不是全宽的)。滚动会使卡片再次变为全宽 msgh_detail.xml中的相关代码 <include android:layout_width="wrap_content" android:layout_height="400dp" layout="@layout/msgh_detail_l
<include
android:layout_width="wrap_content"
android:layout_height="400dp"
layout="@layout/msgh_detail_list" />
下面是实际布局msgh\u详细信息\u列表\u项的代码
<?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>
看起来很简单,以前也很好用
可能我的某些设置或层次结构有点错误。将recyclerView的宽度更改为匹配父项,而不是活动布局中的包装内容。。这导致了问题。您的外部线性布局已关闭ryt??也共享您的活动布局。。我希望您没有制作过recyclerView width
wrap\u content
。。
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);
}
<?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>