我正在制作一个使用相对布局在屏幕上创建透明黑色活动的应用程序,但是它创建的布局与我的手机屏幕的宽度不匹配。
这是我编码的结果
这是我的xml文件。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#A6000000"
>
</RelativeLayout>
</RelativeLayout>
这是我用来创建透明活动的styles.xml
<style name="Theme.Transparent" parent = "android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
我已经为宽度和高度都设置了match_parent。谢谢。
最佳答案
您需要在styles.xml
中为Theme.Transparent
设置此设置:
<item name="android:windowIsFloating">false</item>
浮动窗口通常是一个对话框,因此任一侧都有自动间距。将此设置为false会删除此自动间距。您可以阅读有关in the related documentation的更多信息,特别是:
...该窗口是否以浮动样式显示(基于样式/主题中的
R.attr.windowIsFloating
属性)。虽然,如果您要全屏显示
RelativeLayout
,那么您仍然想知道为什么为什么需要透明度。