如何只对父视图应用动画? [英] How to apply animation only for parent view?

查看:132
本文介绍了如何只对父视图应用动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是相对布局作为父视图和放大器;文字观为孩子..我申请的动画(缩小的效果),以​​父视图,但它也将在其子文本视图。我想申请的动画效果只对父视图

这是适配器getView我的code()方法:

parentView =(RelativeLayout的)convertView.findViewById(R.id.rel_lt);

动画动画= AnimationUtils.loadAnimation(背景下,R.anim.zoom_out);
parentView.setAnimation(动画);


解决方案

使用此布局动画:

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent>< RelativeLayout的
    机器人:ID =@ + ID / rel_lt
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:layout_centerHorizo​​ntal =真
    机器人:背景=#FF890009>
< / RelativeLayout的><的TextView
    机器人:ID =@ + ID / textView1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_centerInParent =真
    机器人:文字=TextView的/>< / RelativeLayout的>


  

不要将动画应用于根RelativeLayout的。只给孩子RelativeLayout的id为@ + ID / rel_lt应用动画。


希望这可以帮助你。

I'm using Relative Layout as parent view & Text View as its child.. I'm applying animation(zoom out effect) to parent view, but it is applying on its child text view also. I want to apply its animation effect only for parent view

This is my code in adapters getView() method :

parentView = (RelativeLayout) convertView.findViewById(R.id.rel_lt);

Animation animation = AnimationUtils.loadAnimation(context, R.anim.zoom_out); parentView.setAnimation(animation);

解决方案

Use this layout for your animation:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
    android:id="@+id/rel_lt"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:background="#FF890009" >
</RelativeLayout>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:text="TextView" />

</RelativeLayout>

Dont apply animation to root RelativeLayout. Apply animation only to the child RelativeLayout with id @+id/rel_lt.

Hope this might help you.

这篇关于如何只对父视图应用动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆