0

この方法を使用して、ListView アイテムのドロップダウン メニューを作成しています。

これが私のアイテムの XML です

<RelativeLayout ...>
  <TableLayout ...>
    <Something like TextView, ImageView... />
    <ImageButton android:id="@+id/btnMenu"... />
  </TableLayout>

  <LinearLayout android:id="@+id/dropMenu" android:visibility="gone" ...>
    <Some other Button... />
  </LinearLayout>
</RelativeLayout>

したがって、「getView(int position, View convertView, ViewGoup parent)」では、ユーザーが「btnMenu」をクリックすると、「dropMenu」が表示され、ドロップダウン メニューのようになります。

私の質問は

  1. 最初に 4 番目の項目をクリックし、そのドロップダウン メニューを表示します
  2. 次に、6 番目の項目をクリックしてドロップダウン メニューを表示しますが、4 番目の項目のドロップダウン メニューは「非表示」に設定する必要があります。

ここに私が試しましたが、うまくいきませんでした

View lastView=getChildAt(lastIndex);
lastView.findViewById(R.id.dropMenu).setVisibility(View.GONE);

実際に6番目のリスト項目にいるときに、4番目のリスト項目を操作するにはどうすればよいですか?

4

1 に答える 1

0

ExpandAnimation を使用して要件を達成できます。

ここに画像の説明を入力

ここに画像の説明を入力

ExpandListItem.java

package com.list.animation;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.LinearLayout.LayoutParams;

public class ExpandListItem 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 ExpandListItem(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;
        }
    }
}

完全な実装については、以下の投稿を参照してください

http://amitandroid.blogspot.in/2013/03/android-listview-with-animation.html

これがあなたを助けることを願っています..ありがとう

于 2013-05-23T11:33:55.067 に答える