主xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="activity"
type="xxx.xxx.xxx.XXActivity" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_bg"
android:orientation="vertical">
<include
android:id="@+id/include"
layout="@layout/include_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
bind:activity="@{activity}" />
</LinearLayout>
</layout>
include 檔案
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<import type="android.view.View" />
<data>
<variable
name="ctivity"
type="xxx.xxx.xxx.XXActivity" />
</data>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="@{()->activity.dealClick()}">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="https://bbs.csdn.net/topics/@mipmap/ic_placeholder" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="12dp" />
</FrameLayout>
</layout>
include檔案是個通用布局,比如上邊欄,這個點擊事件是回傳上一頁,用findviewbyid的時候,因為id一樣,點擊事件也是一樣的代碼即可。但是用databinding,由于要傳入activity,不同的activity肯定是不能通用了。
有什么解決辦法么?
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/239777.html
標籤:Android
上一篇:【大廠訣竅】Android開發3年當了2年咸魚每天CRUD,復習2個月幸運拿下美團offer!
下一篇:學習flutter前景如何?
