編輯:關於Android編程
方法一layout:
public void init(){
ImageView popimg=(ImageView) findViewById(R.id.pop_img);
popimg.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
LinearLayout layout = new LinearLayout(ShowPopwindow.this);
layout.setBackgroundColor(Color.GRAY);
TextView tv = new TextView(ShowPopwindow.this);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
tv.setText(I'm a pop -----------------------------!);
tv.setTextColor(Color.WHITE);
layout.addView(tv);
// 設置相關屬性
popwindow = new PopupWindow(layout,w,h);
// 設置動畫效果
popwindow.setFocusable(true);
popwindow.setOutsideTouchable(true);
popwindow.setBackgroundDrawable(new BitmapDrawable());
popwindow.showAsDropDown(et, 0, 1);
// int[] location = new int[2];
// v.getLocationOnScreen(location);
// popwindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0], location[1]-popwindow.getHeight());
}
});
}
方法二自定義布局:
public void initPopuptWindow(){
ImageView popimg=(ImageView) findViewById(R.id.pop_img);
popimg.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater)ShowPopwindow.this
.getSystemService(LAYOUT_INFLATER_SERVICE);
View v1 = inflater.inflate(R.layout.pop_listview, null);
EditText et1 = (EditText) v1.findViewById(R.id.et1);
w=et.getWidth();
h=et.getHeight();
Log.e(INFO, w+===+h);
// 設置相關屬性
popwindow = new PopupWindow(v1,w,h);
// 設置動畫效果
popwindow.setFocusable(true);
popwindow.setOutsideTouchable(true);
popwindow.setBackgroundDrawable(new BitmapDrawable());
popwindow.showAsDropDown(et, 0, 1);
}
});
}
XML代碼:
代碼完畢!
小米Note支持內存卡(TF)擴展嗎
小米Note是一款性能非常不錯的雙卡雙待手機,高清電影/電視劇、精彩的手機游戲肯定不在話下,但是高清視頻、手游都動辄1GB以上,小米Note的容量夠用嗎?如
Android 集成支付寶支付詳解
一說到支付寶,相信沒有人不知道,生活中付款,轉賬都會用到。今天來詳細介紹下在android中如何集成支付寶支付到自己的APP中去。讓APP能夠擁有方便,快捷的支付功能。准
android自定義布局的使用!
繼承viewGroup; 自定義控件的左邊距;右邊距;上邊距,下邊距; java 代碼; package com.example.customview1406_04m
RecycleView進階三(實現不一樣的拖動排序以及側滑刪除)
前言:上次呢為大家介紹了如何給RecycleView添加頭部、尾部達到裝飾的效果,那麼本章節將為大家介紹RecycleView實現不一樣的拖動排序以及側滑刪除。首先呢我們