1
我想實現一個彈出窗口與列表視圖。當我在listview中添加項目時,它將填充錨點視圖下方的屏幕。彈出窗口與列表視圖不包裝
基本上我的列表視圖不包裝。 以下是圖像和代碼,我使用: -
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// ToolTipView toolTipView = new ToolTipView(MainActivity.this, "");
// toolTipView.setText("swfwefw wefwe8732ryf89 8yu2fc h8wuijcb8unwi ");
// toolTipView.show(v);
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popupwindoiw, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ListView btnDismiss = (ListView)popupView.findViewById(R.id.list);
final ArrayList<String> list = new ArrayList<String>();
list.add("hello");
list.add("helloworld");
list.add("helloexzeo");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, R.layout.list_row, list);
btnDismiss.setAdapter(adapter);
btnDismiss.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Toast.makeText(MainActivity.this, list.get(arg2), Toast.LENGTH_SHORT).show();
popupWindow.dismiss();
}
});
popupWindow.showAsDropDown(v);
}
});
popwindow.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white" >
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ListView>
</RelativeLayout>
list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical" />
在圖像中,目前的ListView在紅色區域顯示,但我想在藍色區域。
,因爲我支持多種屏幕尺寸
儘量給你popwindow佈局固定寬度。 – GrIsHu
Popupwindow位置可以在任何地方也..我已經提到。不能給寬度。必須包裝 –