[英]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.