简体   繁体   English

如何在Android Studio布局编辑器中知道布局的总高度和宽度?

[英]How can I know my layout's total height and width in Android Studio layout editor?

I am designing a layout for a Notification with Custom View using Android Studio Layout Editor and Text. 我正在使用Android Studio布局编辑器和文本设计带有自定义View的通知的布局。 But according to the Android Developer site there is a caution to this given as: 但是根据Android开发者网站的说法,请注意以下几点:

Caution: When you use a custom notification layout, take special care to ensure that your custom layout works with different device orientations and resolutions. 注意:使用自定义通知布局时,请格外小心,以确保自定义布局可在不同的设备方向和分辨率下使用。 While this advice applies to all UI layouts, it's especially important for notifications because the space in the notification drawer is very restricted. 尽管此建议适用于所有UI布局,但对于通知尤为重要,因为通知抽屉中的空间非常有限。 The height available for a custom notification layout depends on the notification view. 自定义通知布局的可用高度取决于通知视图。 Usually, collapsed view layouts are limited to 64 dp, and expanded view layouts are limited to 256 dp. 通常,折叠视图的布局限制为64 dp,展开视图的布局限制为256 dp。

And can be found in this link in the developer site . 并且可以在开发人员站点的此链接中找到。 So for my layout to look good in all devices it should be around 64dp for collapsed and 256dp for expanded views. 因此,要使我的布局在所有设备上看起来都不错,对于折叠的视图应为64dp,对于展开的视图应为256dp。

So the question is how will I know the total height of the Layout given all my TextView s are single line and ellipsized end using Android Studio layout editor? 所以问题是,使用Android Studio布局编辑器,如果我所有的TextView均为单行和椭圆形end我将如何知道Layout的总高度? What is a workaround to calculate the paddings, margins, textsizes, view sizes and give the whole height of a layout? 有什么解决方法可以计算出内边距,边距,文本大小,视图大小并给出整个布局的高度? And if it is NOT possible in Android Studio layout editor what is a alternative to avoid adjust and run, adjust and run, adjust and run...? 并且,如果在Android Studio布局编辑器中无法实现,还有什么方法可以避免调整和运行,调整和运行,调整和运行...?

You need to dynamic get the screen size inside the code and get, change and save back to the view's layoutparams if you require fully control. 如果需要完全控制,则需要动态获取代码中的屏幕尺寸,然后获取,更改并保存回视图的layoutparams。

Better approach in Android studio is you design the layout xml specific for each screen config, such as added a directory of layout named layout-xlarge for large device, also you can build a value-xlarge directory and added a dimens.xml file and set various value (for example 40dp) for different config, and get it inside the layout.xml (@dimen/dimenxxxsize). 在Android Studio中,更好的方法是为每个屏幕配置设计特定的布局xml,例如为大型设备添加名为layout-xlarge的布局目录,还可以构建value-xlarge目录并添加dimens.xml文件并进行设置用于不同配置的各种值(例如40dp),并将其放入layout.xml(@ dimen / dimenxxxsize)中。

please reference of below: https://developer.android.com/training/multiscreen/screensizes.html 请参考以下内容: https : //developer.android.com/training/multiscreen/screensizes.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM