Android 表格行的淡出动画
我有一个带有 TextView
的 TableRow
。这是它的 xml。
<TableRow
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:background="#BF000000">
<TextView
android:id="@+id/topText"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="19sp"
android:background="#BF000000"
android:layout_gravity="center_horizontal"
android:text="@string/text_searchword"
android:layout_width="fill_parent">
</TextView>
</TableRow>
我想通过按钮触摸时的淡出效果使表格行不可见,反之亦然。我该怎么做呢?
I have a TableRow
with a TextView
. Here is the xml for it.
<TableRow
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:background="#BF000000">
<TextView
android:id="@+id/topText"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="19sp"
android:background="#BF000000"
android:layout_gravity="center_horizontal"
android:text="@string/text_searchword"
android:layout_width="fill_parent">
</TextView>
</TableRow>
I want to make the table row invisible with fadeout effect on a button touch and vice versa. How can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
任何
View
(包括TableRow
)都可以附加淡入淡出动画,但您需要能够在代码中引用您的视图,因此该行需要一个id:现在您可以在 Java 代码中的某处引用该行本身(也许是
onCreate()
),请注意,我不会将其转换为
TableRow
。如果您需要用它做其他事情,您可以,但仅设置可见性,将其保留为视图就可以了。然后只需构造一个按钮单击方法,如下所示:Fade in 和 Fade out 是 Android 包中定义的标准动画,您不需要自己创建它们,只需使用
AnimationUtils.loadAnimation()
加载它们即可。在此示例中,单击同一按钮只会在淡入和淡出之间切换,具体取决于视图是否已经可见。希望有帮助!
Any
View
(TableRow
included) can have a fade animation attached to it, but you'll need to be able to reference your view in code, so the row will need an id:Now you can reference the row itself in your Java code somewhere (like
onCreate()
perhaps) asNotice I don't cast it as a
TableRow
. You could if you need to do other things with it, but for just setting visibility leaving it as a View is fine. Then just construct a button click method like this:Fade in and Fade out are standard animations defined in the Android package, you don't need to create them yourself, just load them using
AnimationUtils.loadAnimation()
. In this example, the clicking the same button just toggles between fade in and fade out depending on whether or not the View is already visible.Hope that Helps!