嘿,我有一个从屏幕顶部到屏幕底部之前的滚动视图,因为这是我的广告横幅发生的地方.由于谷歌政策,我想在这些元素之间(按钮和横幅之间)有一些像素.到目前为止,我在dp中设置了一个值.但是,由于设备不同,这导致广告与某些高分辨率手机上的滚动视图之间存在巨大差距.这就是为什么我要设置
<ScrollView
android:layout_height="(Screen_height-banner)-5px"
Run Code Online (Sandbox Code Playgroud)
(当然我甚至没有以这种方式尝试,因为这不是代码,但我认为它总结得很好我计划做什么)
非常感谢你的回答!
您无法在 XML 中查询屏幕尺寸,因为它不在运行时运行,您可以通过使用RelativeLayout
和 usealignments
来执行此操作margins
。
在您的情况下,如果 Screen_height-banner 代表屏幕高度,并且您希望将其放置在底部并从末尾创建 5dp 分隔符,您的 XML 将是
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp">
</RelativeLayout >
Run Code Online (Sandbox Code Playgroud)
如果您需要缩放滚动视图而不是定位它,您的 xml 将会是
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding_bottom="5dp">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent">
</RelativeLayout >
Run Code Online (Sandbox Code Playgroud)