我有一個Activity
,其中包含一個Gallery
視圖。我在Gallery
上定義了一個onItemSelectedListener
,所以無論何時選擇一個項目,我都會將一個比例動畫應用到當前選定的視圖。聆聽者和縮放的工作方式與預期相似,除了一個問題。Android圖庫縮放中心圖像和間距問題
當我定義圖庫時,我設置了spacing
屬性,但是在縮放視圖之後,間距未被正確設置。請參閱下面的圖像作爲問題的示例。
有關如何保持適當間距的任何想法?
下面是代碼的片段:
main.xml中
<Gallery
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/featured_gallery"
android:layout_width="1355px"
android:layout_height="490px"
android:layout_gravity="center"
android:spacing="5px"
android:layout_marginTop="70dp"
/>
feature_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1.0"
android:toXScale="1.075"
android:fromYScale="1.0"
android:toYScale="1.075"
android:duration="100"
android:pivotX="50%"
android:pivotY="50%"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fillAfter="true">
</scale>
onItemSelectListener
private class FeaturedSelectListener implements AdapterView.OnItemSelectedListener {
private Animation grow = null;
private View lastView = null;
public FeaturedSelectListener(Context c) {
grow = AnimationUtils.loadAnimation(c, R.anim.featured_selected);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// Shrink the view that was zoomed
try {
if (null != lastView)
lastView.clearAnimation();
} catch (Exception clear) {
}
// Zoom the new selected view
try {
view.startAnimation(grow);
} catch (Exception animate) {
}
// Set the last view so we can clear the animation
lastView = view;
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
您是否嘗試在所選圖像上設置左右邊距?也許它可以幫助你。 – Andreas
我剛剛嘗試過,但不幸的是,這沒有奏效。如果我從動畫中刪除了pivotX,則縮放視圖的左側會有間距,但不是右側。右側的項目沒有正確移動。 – Steve
你好史蒂夫,我需要在圖庫中做同樣的動畫,如果你已經達到了這個目標,你可以給我發送代碼嗎? – Hasmukh