1.跑马灯效果的Textview
<style name="pull_marquee_style">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:clickable">true</item>
<item name="android:ellipsize">marquee</item>
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:singleLine">true</item>
<item name="android:marqueeRepeatLimit">marquee_forever</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textColor">@color/white</item>
<item name="android:textSize">12sp</item>
</style>
重点是<item name="android:singleLine">true</item>
这行改成<item name="android:lines">1</item>
的话就不行了。
2.RxJava与DataBinding共用的一个问题
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
mUser = new User("Test", "User");
binding.setUser(mUser);
mUser.setFirstName("修改后1");
mService = getRetrofit().create(PullService.class);
MyParams params = new MyParams();
params.put("roomnumber", "123");
mService.getRoomInfo(params.get())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
new Action1<Bean>() {
@Override
public void call(Bean s) {
mUser.setFirstName("修改后2");
}
});
}
这样写的话,mUser这个变量数据虽然已经写进去了,但是绑定的view不会更新的。暂时找不到很好的办法,只能
new Action1<Bean>() {
@Override
public void call(Bean s) {
mUser.setFirstName("修改后2");
binding.textView.setText(s.getMsg());
}
});
这样手动去设置一下了。
Edit:知道原因了,是需要ViewModel继承BaseObservable的,如下:
public class User extends BaseObservable{
private String firstName;
private String lastName;
public void setFirstName(String firstName) {
this.firstName = firstName;
notifyPropertyChanged(BR.firstName);
}
public void setLastName(String lastName) {
this.lastName = lastName;
notifyPropertyChanged(BR.lastName);
}
public User(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
@Bindable
public String getFirstName() {
return this.firstName;
}
@Bindable
public String getLastName() {
return this.lastName;
}
@Override
public String toString() {
return "User{" +
"firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
'}';
}
}
分三步:1.继承BaseObservable 2.为getter方法注解@Bindable 3.setter方法内写notifyPropertyChanged(BR.xxx);之前没这么写是因为发现不用这样写也能出发UI变化,所以以为是新的sdk把操作简化了,原来还是要按官网的操作来的。
3.还是DrawerLayout的抽屉全屏问题
找到了一个更好的方案,不在xml里设置-64dp,而是在代码去动态读取当前window的信息,然后设置抽屉部分的宽度为窗口的宽度就行了。如下:
/** * 由于官方的drawer定死了拉出时与另一边的距离,在这个方法里使drawer布满整个屏幕 */
private void drawerMaximize() {
DisplayMetrics metric = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metric);
int windowsWight = metric.widthPixels;
View leftMenu = findViewById(R.id.nav_frag_container);
ViewGroup.LayoutParams leftParams = leftMenu.getLayoutParams();
leftParams.width = windowsWight;
leftMenu.setLayoutParams(leftParams);
}