Android integer xml资源值不为';在纵向和横向之间切换时不会发生变化
我使用以下GradientDrawable作为相对论的背景:Android integer xml资源值不为';在纵向和横向之间切换时不会发生变化,android,android-resources,landscape-portrait,Android,Android Resources,Landscape Portrait,我使用以下GradientDrawable作为相对论的背景: <shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:angle="@integer/my_value" android:endColor="#0FFF" android:startColor="#FFFF" /> </shape&g
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="@integer/my_value"
android:endColor="#0FFF"
android:startColor="#FFFF" />
</shape>
然后在res\values文件夹中创建了一个名为integers.xml的文件:
<resources>
<integer name="my_value">90</integer>
</resources>
<resources>
<integer name="my_value">180</integer>
</resources>
90
以及res\values land文件夹下另一个同名文件:
<resources>
<integer name="my_value">90</integer>
</resources>
<resources>
<integer name="my_value">180</integer>
</resources>
180
因此,当我旋转设备时,在运行Android 2.3.3(如预期)时,渐变从下->上到右->左,但当我在Android 4.4.4上测试时,渐变角度不会改变。
我也尝试过:
<item name="my_value" format="float" type="dimen">90</integer>
90
但同样的结果
有什么想法吗?
更新:
使用GradientDrawable的RelativeLayout存在于两个不同的文件中:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/my_drawable" >
更新2:
只有在旋转设备时才会出现问题。如果我在之前旋转设备的情况下开始活动,则正确设置渐变角度。一个快速解决方法是直接使用两种不同的形状:
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:endColor="#0FFF"
android:startColor="#FFFF" />
</shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="180"
android:endColor="#0FFF"
android:startColor="#FFFF" />
</shape>
你用同样的方法吗?在活动使用的xml布局中?有一点我忘了提。我提到的RelativeLayout存在于2个布局文件中。一个用于纵向,另一个用于横向。这真的需要在参考资料中包含这个维度吗?不需要,但我想避免创建两个不同的绘图。它在运行API 10的仿真器中工作正常,但在运行API 19的设备上无法更改。如何在清单中定义活动(从何处调用此活动)?你允许它在方向改变时重画吗?