0
我試圖使用TranslateAnimation
在點擊項目時將個人檔案圖片移動到頂部。使用TranslateAnimation添加項目(來自ListView)不會取出他的父項
我找到了正確的位置(x,y),但個人資料圖片沒有出自他的項目區域。
我試圖使用bringToFront()
方法,但它不起作用。
這裏我的問題
代碼以動畫我看來
public void animateContactAdding(View view) {
View profileImage = view.findViewById(R.id.linear_layout_image_profile);
int positionViewContact[] = {0, 0};
profileImage.getLocationOnScreen(positionViewContact);
int positionHeader[] = {0, 0};
mRelativeLayoutContactHeader.getLocationOnScreen(positionHeader);
float distanceBtwViews = (positionViewContact[1] - positionHeader[1]) * -1;
TranslateAnimation anim = new TranslateAnimation(0, 0, 0, distanceBtwViews);
anim.setDuration(400);
anim.setAnimationListener(new TranslateAnimation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
});
profileImage.startAnimation(anim);
}
項目
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight">
<LinearLayout
android:id="@+id/linear_layout_image_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/circle_image_placeholder"
android:layout_width="?android:attr/listPreferredItemHeight"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="10dp" />
<ImageView
android:id="@+id/circle_image_profile"
android:layout_width="?android:attr/listPreferredItemHeight"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="10dp" />
</LinearLayout>
<TextView
android:id="@android:id/text2"
android:layout_width="match_parent"
android:layout_height="26dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_toEndOf="@+id/linear_layout_image_profile"
android:ellipsize="marquee"
android:lines="1"
android:visibility="gone" />
<TextView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@android:id/text2"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toEndOf="@+id/linear_layout_image_profile"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:lines="1"
android:textAppearance="@style/TextAppearance.RalewaySemiBold"
android:textSize="17sp" />
</RelativeLayout>
我的代碼已經這樣做了。我只是動畫沒有文字的個人資料圖片。 – Johnny
你在佈局中應用動畫嗎?看看這一行:profileImage = view.findViewById(R.id.linear_layout_image_profile); –
哦,好的。是的,我的項目包含一個'LinearLayout',它包含兩個'ImageView'。我直接在'ImageView'上嘗試,看起來完全一樣: -/ – Johnny