android界面下拉效果是如何实现的?求代码。如下图
2个回答
展开全部
public class TopPopup extends PopupWindow{
private LayoutInflater inflater;
private LinearLayout layout;
private ListView listItem;
private String[] StrItems;
private ArrayAdapter<String> 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<String>(mContext,android.R.layout.simple_list_item_1,StrItems);
listItem.setAdapter(adapter);
}
public void setItems(String [] items){
StrItems = items;
}
private LayoutInflater inflater;
private LinearLayout layout;
private ListView listItem;
private String[] StrItems;
private ArrayAdapter<String> 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<String>(mContext,android.R.layout.simple_list_item_1,StrItems);
listItem.setAdapter(adapter);
}
public void setItems(String [] items){
StrItems = items;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询