如何添加动画,以线性布局?线性、布局、动画

由网友(伤痛能耐我何)分享简介:我使用的线性布局得到的消息与.NET服务器映像。i am using linear layout to get the message with image from .net server.当新的消息已经来到的布局的位置增加,新的消息被添加到布局之一的顶端由一个when the new message is c...

我使用的线性布局得到的消息与.NET服务器映像。

i am using linear layout to get the message with image from .net server.

当新的消息已经来到的布局的位置增加,新的消息被添加到布局之一的顶端由一个

when the new message is come the position of the layout is increased and the new message is added to the top of the layout one by one.

问题是,当新的消息会被添加新的消息布局豁然开朗。

the problem is when the new message will come,the new message is added to layout suddenly.

我想申请动画的布局,让我的应用程序一样,当新邮件到来的消息被添加到布局缓慢。意味着previous消息向下移动缓慢,新信息添加布局之上。

i want to apply animation to the layout and make my app like when the new message is come the message is added to the layout slowly. means the previous messages move down slowly and new message is added top of the layout.

如果任何一个有想法,请帮助我。

if any one have idea please help me.

感谢advanse

推荐答案

采用Android:上应持数据的LinearLayout animateLayoutChanges。这将增加新的内容时触发动画。它开始通过移动旧的数据倒腾出更多的内容。然后如下的第二步骤,其中新数据会褪色到自由空间中。

Use android:animateLayoutChanges on the LinearLayout that shall hold the data. This will trigger an animation when adding new content. It starts by moving the old data down making room for more content. Then follows a second step where the new data will fade into the free space.

示例code

的main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/baseLL"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
>

    <!-- button used to add data -->
    <Button
        android:layout_width="192dip"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Add Content"
        android:onClick="onAddContentClick" />

    <!-- button used to remove data -->
    <Button
        android:layout_width="192dip"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Remove Content"
        android:onClick="onRemoveContentClick" />

    <!-- data will be added to this LinearLayout at run time -->
    <LinearLayout
        android:id="@+id/dataLL"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:animateLayoutChanges="true"
    >

    </LinearLayout>

</LinearLayout>

basicanimation.java

package com.test.animation.basic;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class BasicAnimationActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void onAddContentClick(View v) {
        LinearLayout dataLL = (LinearLayout) findViewById(R.id.dataLL);
        int dataCount = dataLL.getChildCount();
        TextView newDataTV = generateData(dataCount);
        dataLL.addView(newDataTV, 0);
    }

    public void onRemoveContentClick(View v) {
        LinearLayout dataLL = (LinearLayout) findViewById(R.id.dataLL);
        if (dataLL.getChildCount() > 0) {
            dataLL.removeViewAt(0);
        }
    }

    private TextView generateData(int dataCount) {
        TextView TV = new TextView(this);
        TV.setText("Data " + dataCount);
        TV.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
        return TV;
    }
}
阅读全文

相关推荐

最新文章