Tol*_*yas 7 xml android android-studio
我需要在layer-list中设置item的大小.用于在启动活动中用作windowBackground.我写了这个XML文件,Android Studio正确显示它.但在应用程序中,徽标始终全屏.怎么做?
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:endColor="#000004"
android:gradientRadius="1000"
android:startColor="#1f3371"
android:type="radial" >
</gradient>
</shape>
</item>
<item>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/texture_5"
android:tileMode="repeat" />
</item>
<item android:drawable="@drawable/logo"
android:height="100dp"
android:width="77dp"
android:gravity="center"
>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
我找到了解决方案,但我期待更好的方法.这是最终代码:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:endColor="#000004"
android:gradientRadius="1000"
android:startColor="#1f3371"
android:type="radial" >
</gradient>
</shape>
</item>
<item>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/texture_5"
android:tileMode="repeat" />
</item>
<item android:drawable="@drawable/logo"
android:bottom="214dp"
android:top="214dp"
android:left="100dp"
android:right="100dp"
android:gravity="center"
android:tileMode="repeat"
>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
至少它在xxhdpi和xhdpi上工作而没有失真.
从API 23开始,可以在“ item”标签内直接设置宽度和高度:
<item android:drawable="@drawable/logo" android:width="..." android:height="..." />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12332 次 |
| 最近记录: |