Sky*_*ius 22 android android-layout android-tv
我正在尝试制作一个带有a的水平列表RecyclerView,当我将焦点放在一个项目上时,增加它的大小.我想这样做:
你有什么想法来实现这个目标吗?
Seb*_*ano 18
我想象的是这样的:
FocusChangeListener到项目的根视图static class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(View root) {
// bind views
// ...
// bind focus listener
root.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
// run scale animation and make it bigger
} else {
// run scale animation and make it smaller
}
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
Sky*_*ius 14
感谢dextor的回答,我可以找出这个答案。
我已经使用FocusChangeListener和 添加的动画状态来更改视图的大小:
static class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(final View root) {
// bind views
// ...
// bind focus listener
root.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
// run scale animation and make it bigger
Animation anim = AnimationUtils.loadAnimation(context, R.anim.scale_in_tv);
root.startAnimation(anim);
anim.setFillAfter(true);
} else {
// run scale animation and make it smaller
Animation anim = AnimationUtils.loadAnimation(context, R.anim.scale_out_tv);
root.startAnimation(anim);
anim.setFillAfter(true);
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
以及动画的代码:
scale_in_tv:
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXScale="100%"
android:fromYScale="100%"
android:toXScale="110%"
android:toYScale="110%"
android:pivotX="50%"
android:pivotY="50%">
</scale>
Run Code Online (Sandbox Code Playgroud)
scale_out_tv:
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="100"
android:fromXScale="110%"
android:fromYScale="110%"
android:toXScale="100%"
android:toYScale="100%"
android:pivotX="50%"
android:pivotY="50%">
</scale>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8192 次 |
| 最近记录: |