View的大小?PopuupWindow应用

ihrthk
博客专家认证
2013-01-28 04:44:36
popup_more_account.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200.0dip"
android:layout_height="wrap_content"
android:background="@drawable/backgroundport"
android:orientation="vertical" >

<ListView
android:id="@+id/lv_popup_accounts"
android:layout_width="200.0dip"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:listSelector="@drawable/list_selector" >
</ListView>

</LinearLayout>


item_account_list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:padding="5dip" >

<TextView
android:id="@+id/txt_user_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:singleLine="true"
android:text="20101681"
android:textColor="@color/black"
android:textSize="20.0dip" />

<ImageButton
android:id="@+id/txt_user_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dip"
android:background="@drawable/btn_delete_user"
android:focusable="false"
android:textSize="15.0dip" />

</LinearLayout>




View moreAccountView = LayoutInflater.from(LoginActivity.this)
.inflate(R.layout.popup_more_account, null);

ListView lvAccounts = (ListView) moreAccountView
.findViewById(R.id.lv_popup_accounts);
ListViewAccountAdapter adapter = new ListViewAccountAdapter(
LoginActivity.this);
lvAccounts.setAdapter(adapter);

lvAccounts.measure(0, 0);
int height = lvAccounts.getMeasuredHeight();

PopupWindow mPopupWindow = new PopupWindow(moreAccountView,
edtAccount.getWidth(), height);
Drawable backgroup = LoginActivity.this.getResources()
.getDrawable(R.drawable.transparent);
mPopupWindow.setBackgroundDrawable(backgroup);

int pos[] = new int[2];
edtAccount.getLocationOnScreen(pos);

mPopupWindow.showAtLocation(edtAccount, Gravity.LEFT
| Gravity.TOP, pos[0], pos[1] + edtAccount.getHeight());

我想要的效果就是moreAccountView里多少内容,moreAccountView就有多高,请问怎么实现?

...全文
107 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ihrthk 2013-01-29
  • 打赏
  • 举报
回复
自顶一下,求解。

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧