##Android Data Binding 代码实战
本代码用来练习Android Data Binding技术
###目前实现
豆瓣电影搜索
利用Data Binding在RecycleView展示电影列表
![data-binding-example](/images/data-binding-example.png)
###Model
```java
public class Movie extends BaseObservable {
private String id;
private String title;
private String original_title;
private String year;
private Images images;
private Rating rating;
@Bindable
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
notifyPropertyChanged(BR.title);
}
@Bindable
public String getDescription() {
return this.original_title + "\n" + this.getYear();
}
public void setOriginal_title(String original_title) {
this.original_title = original_title;
notifyPropertyChanged(BR.description);
}
public void setYear(String year) {
this.year = year;
notifyPropertyChanged(BR.description);
}
...
}
```
###Layout
```xml
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="movie"
type="com.aswifter.databinding.model.Movie" />
</data>
...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{movie.title}"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="@color/primary_text" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="@{movie.description}"
android:textColor="@color/secondary_text" />
<RatingBar
style="@android:style/Widget.DeviceDefault.Light.RatingBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:numStars="10"
android:rating="@{movie.rating.average}"
android:stepSize="0.5" />
</LinearLayout>
...
</layout>
```
###Binding
```java
Movie movie = mMovies.get(position);
Glide.with(MovieActitiviy.this)
.load(movie.getImages().getMedium())
.fitCenter()
.into(holder.binding.ivMovie);
holder.binding.setVariable(com.aswifter.databinding.BR.movie, movie);
holder.binding.executePendingBindings();
```
没有合适的资源?快使用搜索试试~ 我知道了~
Android Data Binding 代码实战 demo
共41个文件
xml:17个
png:6个
java:5个
需积分: 9 21 下载量 37 浏览量
2016-12-09
11:35:53
上传
评论
收藏 269KB ZIP 举报
温馨提示
豆瓣电影搜索 利用Data Binding在RecycleView展示电影列表
资源推荐
资源详情
资源评论
收起资源包目录
AndroidDataBindingExample-master.zip (41个子文件)
AndroidDataBindingExample-master
.gitignore 96B
gradle
wrapper
gradle-wrapper.jar 49KB
gradle-wrapper.properties 230B
README.md 3KB
build.gradle 499B
gradlew.bat 2KB
gradlew 5KB
app
.gitignore 7B
build.gradle 1KB
proguard-rules.pro 682B
src
main
AndroidManifest.xml 805B
java
com
aswifter
databinding
model
Movie.java 5KB
User.java 448B
MainActivity.java 1KB
MovieActitiviy.java 4KB
res
values
styles.xml 847B
colors.xml 475B
strings.xml 373B
dimens.xml 254B
mipmap-xxhdpi
ic_launcher.png 8KB
ic_find_in_page_white.png 1KB
layout
activity_main.xml 736B
movie_item.xml 2KB
activity_movie.xml 2KB
mipmap-xhdpi
ic_launcher.png 5KB
mipmap-hdpi
ic_launcher.png 3KB
mipmap-mdpi
ic_launcher.png 2KB
menu
menu_main.xml 361B
values-w820dp
dimens.xml 358B
androidTest
java
com
aswifter
databinding
ApplicationTest.java 355B
gradle.properties 855B
.idea
runConfigurations.xml 564B
vcs.xml 216B
misc.xml 2KB
modules.xml 359B
.name 11B
copyright
profiles_settings.xml 74B
compiler.xml 709B
gradle.xml 608B
images
data-binding-example.png 178KB
settings.gradle 15B
共 41 条
- 1
资源评论
程序猫TheCat
- 粉丝: 18
- 资源: 24
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功