【问题标题】:WebView inside layout which has percentage height except LinearlayoutWebView 内部布局,除 Linearlayout 外,具有百分比高度
【发布时间】:2020-01-31 13:26:06
【问题描述】:

我想将我的 webview 实现放入任何布局中,该布局具有百分比或任何其他内容,使我的 webview 根据它们的大小出现在各种屏幕上。例如,我希望 Web 显示也出现在 30% 的屏幕上。除了 Linearlayout 和 PercentageLayout(已过时),因为我不想更改 xml 根目录。如何实现这个目标?

例如,textview 有 maxline 并且使用 maxline 我们也可以在屏幕上显示文本而无需更改 xml 根目录。

【问题讨论】:

    标签: android android-webview percentage


    【解决方案1】:

    您可以像这样动态地将高度设置为RelativeLayout(Webview的父级)

     int heightInDp=300;
     float scale =getResources().getDisplayMetrics().density;
     int heightInPx = (int) (heightInDp * scale + 0.5f);
     RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(
     ViewGroup.LayoutParams.WRAP_CONTENT,heightInPx);
     rl_parent.setLayoutParams(layout);
    

    【讨论】:

    • 谢谢,但是根据屏幕大小呢?
    猜你喜欢
    • 2012-08-22
    • 2011-09-06
    • 2015-07-06
    • 1970-01-01
    • 2021-10-30
    • 2013-05-19
    • 2014-10-30
    • 1970-01-01
    • 2012-08-31
    相关资源
    最近更新 更多