[英]Animate view that is outside to the screen
我有一个EditText
和TextView
一个内部RelativeLayout
的.The宽度EditText
是match-parent
和TextView
对齐到年底EditText
我想要的是,当用户点击。现在EditText
,其宽度应同时animating.The减少代码工作正常,但是问题是减小宽度后,即使对齐到EditText
的末尾,我也看不到TextView
M
<RelativeLayout
android:id="@+id/ll_search"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/tb_explore"
android:layout_marginLeft="05dp"
android:layout_marginRight="05dp"
android:layout_marginTop="07dp"
android:clipToPadding="false"
android:clipChildren="false"
android:focusable="false">
<RelativeLayout
android:id="@+id/test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/search_view">
<AutoCompleteTextView
android:id="@+id/et_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/imageView11"
android:layout_toStartOf="@+id/imageView11"
android:background="@android:color/transparent"
android:hint="Search by vendor name or keyword"
android:imeOptions="actionGo"
android:padding="10dp"
android:singleLine="true"
android:textSize="@dimen/regular" />
</RelativeLayout>
<TextView
android:id="@+id/tv_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/test"
android:gravity="center"
android:text="Cancel"
android:visibility="visible" />
</RelativeLayout>
动画时减少宽度的代码
ValueAnimator anim = ValueAnimator.ofInt(llSearch.getMeasuredWidth(), llSearch.getMeasuredWidth() - 200);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
if (Constants.isLoggingEnable) {
Logger.logError("Search lenght--", "" + llSearch.getMeasuredWidth());
Logger.logError("Lenght", "" + 500);
Logger.logError("Value of animation--", "" + (Integer) valueAnimator.getAnimatedValue());
}
int val = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = llSearch.getLayoutParams();
layoutParams.width = val;
llSearch.setLayoutParams(layoutParams);
}
});
anim.setDuration(500);
anim.start();
干得好-
ValueAnimator anim = ValueAnimator.ofInt(testLayout.getMeasuredWidth(), testLayout.getMeasuredWidth() - 200);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int val = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = testLayout.getLayoutParams();
layoutParams.width = val;
testLayout.setLayoutParams(layoutParams);
}
});
anim.setDuration(500);
anim.start();
}
其中testLayout是testLayout = (RelativeLayout) findViewById(R.id.test);
。 您应该减小测试布局的宽度。 xml也( 非常微小的变化 )-
<RelativeLayout
android:id="@+id/ll_search"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="05dp"
android:layout_marginRight="05dp"
android:layout_marginTop="07dp"
android:clipChildren="false"
android:clipToPadding="false"
android:focusable="false">
<RelativeLayout
android:id="@+id/test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@color/colorPrimary">
<AutoCompleteTextView
android:id="@+id/et_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:hint="Search by vendor name or keyword"
android:imeOptions="actionGo"
android:padding="10dp"
android:singleLine="true"
android:textSize="12sp"/>
</RelativeLayout>
<TextView
android:id="@+id/tv_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/test"
android:layout_toRightOf="@+id/test"
android:gravity="center"
android:text="Cancel"
android:visibility="visible"/>
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.