カスタムレイアウトに基づくアイテムで表示される親ListViewがあります。ユーザーがアイテムをクリックすると、そのアイテムに子ListViewを追加する必要があり、アニメーションを展開して親ListViewのアイテム全体を表示する必要があります。[すべてのデータを動的に追加する必要があります]提案...
2 に答える
1
2番目のListViewを使用する代わりに、単純なLinearLayoutを使用して動的に設定することを検討することをお勧めします(表示をView.VISIBLEとView.GONEで切り替えます)。私が知っていることから、ListViewsをネストするべきではありません。
于 2012-10-03T15:25:50.507 に答える
1
簡単に、(xmlまたはコードを介して)レイアウトにアイテムを追加し、アニメーションで表示(非表示)することができます。これがUdinicの例です。リストビューアイテムはアニメーションで拡張され、APIレベルは4以上で済みます。この例はとても単純です。linearlayout
あなたは呼び出されたであなたのアイテムを定義するだけですtoolbar
onItemClickイベントでExpanAnimationを使用します
/**
* This animation class is animating the expanding and reducing the size of a view.
* The animation toggles between the Expand and Reduce, depending on the current state of the view
* @author Udinic
*
*/
public class ExpandAnimation extends Animation {
private View mAnimatedView;
private LayoutParams mViewLayoutParams;
private int mMarginStart, mMarginEnd;
private boolean mIsVisibleAfter = false;
private boolean mWasEndedAlready = false;
/**
* Initialize the animation
* @param view The layout we want to animate
* @param duration The duration of the animation, in ms
*/
public ExpandAnimation(View view, int duration) {
setDuration(duration);
mAnimatedView = view;
mViewLayoutParams = (LayoutParams) view.getLayoutParams();
// decide to show or hide the view
mIsVisibleAfter = (view.getVisibility() == View.VISIBLE);
mMarginStart = mViewLayoutParams.bottomMargin;
mMarginEnd = (mMarginStart == 0 ? (0- view.getHeight()) : 0);
view.setVisibility(View.VISIBLE);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t);
if (interpolatedTime < 1.0f) {
// Calculating the new bottom margin, and setting it
mViewLayoutParams.bottomMargin = mMarginStart
+ (int) ((mMarginEnd - mMarginStart) * interpolatedTime);
// Invalidating the layout, making us seeing the changes we made
mAnimatedView.requestLayout();
// Making sure we didn't run the ending before (it happens!)
} else if (!mWasEndedAlready) {
mViewLayoutParams.bottomMargin = mMarginEnd;
mAnimatedView.requestLayout();
if (mIsVisibleAfter) {
mAnimatedView.setVisibility(View.GONE);
}
mWasEndedAlready = true;
}
}
}
詳細な使用法はプロジェクトにあります。
于 2012-10-03T15:29:38.513 に答える