android焦点弹出(缩放)视图
我有一组视图,我想在聚焦时将其“弹出”屏幕;例如,你可能会在视频游戏的菜单中看到这样的东西 为了实现这一点,我在这些视图中添加了一个onfocusChaned侦听器,它在聚焦时运行zoomIn动画,在失去焦点时运行zoomOut动画:android焦点弹出(缩放)视图,android,animation,views,Android,Animation,Views,我有一组视图,我想在聚焦时将其“弹出”屏幕;例如,你可能会在视频游戏的菜单中看到这样的东西 为了实现这一点,我在这些视图中添加了一个onfocusChaned侦听器,它在聚焦时运行zoomIn动画,在失去焦点时运行zoomOut动画: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ViewGroup base = (ViewGro
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
ViewGroup base = (ViewGroup) this.getLayoutInflater().inflate(R.layout.gridtest, null);
ViewGroup container = (ViewGroup) base.getChildAt(0);
this.animZoomIn = AnimationUtils.loadAnimation(this, R.anim.zoomin);
this.animZoomOut = AnimationUtils.loadAnimation(this, R.anim.zoomout);
int x=0;
for(View child:this.getViews(container))
{
ImageView i = (ImageView) child;
i.setPadding(10,10,10,10);
if(x==0) { i.setBackgroundColor(Color.RED); x++; }
else if(x==1) {i.setBackgroundColor(Color.GREEN); x++; }
else if(x==2) {i.setBackgroundColor(Color.BLUE); x=0; }
i.setTag(GridActivity.TAG_EMPTY);
i.setOnFocusChangeListener(new View.OnFocusChangeListener()
{
@Override
public void onFocusChange(View v, boolean hasFocus)
{
if (hasFocus)
{
v.startAnimation(GridActivity.this.animZoomIn);
}
else
{
v.startAnimation(GridActivity.this.animZoomOut);
}
}
});
}
setContentView(base);
}
zoomin.xml:
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:zAdjustment="top"
android:fillEnabled="true"
android:fillAfter="true"
android:fromXScale="1.0"
android:toXScale="1.2"
android:fromYScale="1.0"
android:toYScale="1.1"
android:pivotX="50%"
android:pivotY="50%"
android:duration="200" />
zoomout.xml:
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:zAdjustment="bottom"
android:fromXScale="1.2"
android:toXScale="1.0"
android:fromYScale="1.1"
android:toYScale="1.0"
android:duration="50" />
只要视图能够正确放大和缩小,这一点就可以实现,但是视图的z顺序不会改变。。。因此,“弹出”视图与右侧的(较小)视图重叠
我尝试过使用v.bringToFront(),但这似乎会将聚焦视图移动到父布局的末尾,而不是实际按z方向重新排序
(编辑)
这就是我想要复制的效果
您是否尝试过使用gridtest布局的FrameLayout?您能详细说明一下吗?gridtest.xml中的父布局是什么?FrameLayout允许将视图放置在其他视图之上,因此bringToFront()不应移动视图的位置。然后,查看屏幕截图,我猜父视图是线性布局。框架布局不适合这种情况。。。根据谷歌的说法:“一般来说,FrameLayout应该用来保存单个子视图,因为很难以一种可以扩展到不同屏幕大小的方式来组织子视图,而不让子视图相互重叠。”你解决了这个问题吗?我也有同样的问题与RecyclerView,不知道如何处理它