gpt4 book ai didi

android - 我想在运行时根据 android 中的标题大小设置弹出宽度

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:13:48 25 4
gpt4 key购买 nike

我尝试了很多东西但没有得到任何解决方案,我在运行时设置文本并且我需要根据文本大小弹出窗口的宽度 LinearLayout viewGroup = (LinearLayout) ((Activity) 上下文) .findViewById(R.id.popup);

        LayoutInflater layoutInflater = (LayoutInflater) context

.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);
title_tv = (TextView) layout.findViewById(R.id.popup_txt);

title_tv.setText(title_P);


PopupWindow popup = new PopupWindow(context);
final float SCALE = layout.getResources().getDisplayMetrics().density;
int mode = MeasureSpec.getMode(View.MeasureSpec.UNSPECIFIED);
int measuredWidth = MeasureSpec.getSize(View.MeasureSpec.UNSPECIFIED);
popup.setWidth(measuredWidth);
popup.setHeight(60);


popup.setContentView(layout);
//popup.setWindowLayoutMode();

popup.setFocusable(true);

最佳答案

使用:

popup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);

另外,如果适用:

popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);

但是,请确保您没有在 popup_layout 的内容中使用 fill/match_parent,因为这没有意义(即弹出窗口设置为包装其内容,内容说让我和我的 parent 一样大)。发布您的 popup_layout XML 以获得更准确的答案。

关于android - 我想在运行时根据 android 中的标题大小设置弹出宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14156429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com