Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 通过动画增加线性布局的高度_Android_Animation_Android Linearlayout - Fatal编程技术网

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

Android 通过动画增加线性布局的高度,android,animation,android-linearlayout,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_heigh

我想在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"
    >

您可以这样编写自定义线性布局:

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;
}
}

然后在活动中找到线性布局并开始动画:

 customLayout = (CustomLinearLayout) findViewById(R.id.cl);
    ObjectAnimator oa = ObjectAnimator.ofInt(customLayout, "layoutHeight", DensityUtil.dip2px(this, 200), DensityUtil.dip2px(this, 300));
    oa.setDuration(2000);
    oa.start();

不,它不起作用。线性布局的高度没有改变我运行了我写的代码,这很有效,请更新您的代码@PranavAgrawal
 customLayout = (CustomLinearLayout) findViewById(R.id.cl);
    ObjectAnimator oa = ObjectAnimator.ofInt(customLayout, "layoutHeight", DensityUtil.dip2px(this, 200), DensityUtil.dip2px(this, 300));
    oa.setDuration(2000);
    oa.start();