通过动画增加线性布局的高度

时间:2015-07-05 13:40:00

标签: android animation android-linearlayout

我想在2秒后增加线性布局的高度。 加载活动时,应用程序应等待2秒,然后线性布局的高度应从200dp增加到300dp。 xml代码如下所示。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fffafaf9"
android:clipChildren="false"

 tools:context=".MainActivity">

<TextView android:text="@string/hello_world"
    android:id="@+id/top"
    android:layout_width="wrap_content"
    android:layout_height="60dp"
    android:paddingTop="30dp"
    android:paddingLeft="20dp"
    />

<View
    android:layout_width="fill_parent"
    android:layout_height="2dp"
    android:layout_below="@id/top"
    android:background="#ffd3d3d2" />
<LinearLayout android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:layout_alignParentBottom="true"
    android:orientation="vertical">

    <View
    android:id="@+id/temp_view"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:visibility="visible"
    android:translationZ="20dp"

    android:layout_gravity="center_horizontal"
    android:background="@drawable/circle_shape"
    />

<LinearLayout

    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:layout_marginTop="-80px"
    android:background="#ffe4e4e3"
    android:elevation="-10dp"
    android:alpha="0.5"
    android:layout_below="@id/temp_view"
    >

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

您可以像这样编写自定义LinearLayout:

SELECT calldate, from_unixtime(FLOOR(UNIX_TIMESTAMP(calldate)/(60*60))*(60*60)) GroupTime
 , COUNT(*) as CntOut FROM asterisk.cdr 
 WHERE accountcode = '10102-131' AND DATE (calldate) = DATE (NOW()) AND calltype = 'outgoing' 
 GROUP BY GroupTime;

}

然后在您的活动中找到LinearLayout并开始动画:

public class CustomLinearLayout extends LinearLayout {

private int mLayoutHeight;

public CustomLinearLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public void setLayoutHeight(int height) {
    mLayoutHeight = height;
    ViewGroup.LayoutParams lp = getLayoutParams();
    lp.height = height;
    setLayoutParams(lp);
}

public int getLayoutHeight() {
    return mLayoutHeight;
}