android界面下拉效果是如何实现的?求代码。如下图

2024-11-23 02:26:52
推荐回答(2个)
回答1:

public class TopPopup extends PopupWindow{
private LayoutInflater inflater;
private LinearLayout layout;
private ListView listItem;
private String[] StrItems;
private ArrayAdapter adapter;

private Context mContext;
public TopPopup(Context context) {
super(context);
mContext = context;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = (LinearLayout) inflater.inflate(R.layout.bottom_popup,
null);
setContentView(layout);

// 设置弹出窗体的宽
this.setWidth(200);
// 设置弹出窗体的高
this.setHeight(LayoutParams.WRAP_CONTENT);
// 设置弹出窗体可点击
this.setFocusable(true);
// 设置弹出窗体动画效果
this.setAnimationStyle(R.style.MainPopupAnim);

listItem = new ListView(context);

layout.addView(listItem);
}

public void show(View parent) {

///显示在制定控件的下方
this.showAsDropDown(parent);

adapter = new ArrayAdapter(mContext,android.R.layout.simple_list_item_1,StrItems);

listItem.setAdapter(adapter);
}

public void setItems(String [] items){
StrItems = items;
}

回答2:

actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actionBar.setListNavigationCallbacks(adapter,new DropDrowListener());