出现了一个界面只有一个子项的情况,这是为什么呢?
因为子项的布局中,把子项的root element布局高度设为了match_parent。
<?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"
android:orientation="horizontal">
<ImageView
android:id="@+id/recycler_item_img"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:scaleType="fitXY"/>
<TextView
android:id="@+id/recycler_item_text"
android:layout_weight="5"
android:layout_width="0dp"
android:layout_height="50dp" />
</LinearLayout>
从非Activity中启动activity
第一个是flag
第二个是context如何初始化
viewHolder.textView.setOnClickListener(v -> {
//没有context初始化的时候,编译期不报错,但是运行期报错
context = v.getContext();
// Activity activity = (Activity) v.getContext();
Intent intent = new Intent(context, ItemContext_activity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
});
使用ArrayList
一定要在声明的时候new,把地址空间给分配了
不然是没有办法进行list.add之类的操作的
使用databinding时
在尝试使用databind的时候,把item实体类对象的变量变成了ObservableField
然后再初始化RecyclerView的时候出错了因为:
Observable也一定要先new才能用的