我正在使用这种方式制作我的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”设置为可见,这看起来就像一个下拉菜单。
我的问题是
这是我尝试但没有工作
View lastView=getChildAt(lastIndex);
lastView.findViewById(R.id.dropMenu).setVisibility(View.GONE);
当我实际进入第6个列表项时,如何操作第4个列表项?
答案 0 :(得分: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
希望这会对你有所帮助..谢谢