如何旋转线的Android XML? [英] How rotate line in Android XML?
问题描述
我想绘制与XML的Android应用程序的对角线,但它不工作。它只是简单地画一条水平线。
的main.xml
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:paddingBottom会=@扪/ activity_vertical_margin
机器人:以下属性来=@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_margin
机器人:paddingTop =@扪/ activity_vertical_margin
工具:上下文=TestActivity。>
< RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_alignParentLeft =真
机器人:layout_alignParentTop =真
风格=@风格/ diagonalStyle>
< / RelativeLayout的>
< / RelativeLayout的>
styles.xml
<资源的xmlns:机器人=http://schemas.android.com/apk/res/android>
<样式名称=diagonalStyle>
<项目名称=机器人:背景> @可绘制/背景< /项目>
< /风格>
< /资源>
background.xml
< XML版本=1.0编码=UTF-8&GT?;
<层列表的xmlns:机器人=http://schemas.android.com/apk/res/android>
<项目>
<旋转
机器人:fromDegrees =0
机器人:toDegrees =45
机器人:pivotX =50%
机器人:pivotY =50%>
<形状
机器人:形状=行
机器人:顶部=1dip>
<中风
机器人:宽=1dip
机器人:颜色=#FF0000/>
< /形状>
< /旋转>
< /项目>
< /层列表>
您真的只需要一个号码更改为得到它的工作。只是改变fromDegrees 45:
<项目>
<旋转
机器人:fromDegrees =45
机器人:toDegrees =45
机器人:pivotX =50%
机器人:pivotY =50%>
<形状
机器人:形状=行
机器人:顶部=1dip>
<中风
机器人:宽=1dip
机器人:颜色=#FF0000/>
< /形状>
< /旋转>
< /项目>
在旋转绘制<一href="http://developer.android.com/reference/android/graphics/drawable/RotateDrawable.html">http://developer.android.com/reference/android/graphics/drawable/RotateDrawable.html
实际使用的物业动画格式为:<一href="http://developer.android.com/guide/topics/resources/animation-resource.html">http://developer.android.com/guide/topics/resources/animation-resource.html
而你是一个非动画对角线,你想让它开始了在45度,并最终在45度也。所以他们两个设置为45是正常的。
I'm trying to draw a diagonal line in an Android app with the XML, but it is not working. It simply draws a horizontal line.
main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".TestActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
style="@style/diagonalStyle">
</RelativeLayout>
</RelativeLayout>
styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="diagonalStyle">
<item name="android:background">@drawable/background</item>
</style>
</resources>
background.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<rotate
android:fromDegrees="0"
android:toDegrees="45"
android:pivotX="50%"
android:pivotY="50%" >
<shape
android:shape="line"
android:top="1dip" >
<stroke
android:width="1dip"
android:color="#FF0000" />
</shape>
</rotate>
</item>
</layer-list>
You really only needed one number change to get it to work. Just Change the fromDegrees to 45:
<item>
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="50%"
android:pivotY="50%" >
<shape
android:shape="line"
android:top="1dip" >
<stroke
android:width="1dip"
android:color="#FF0000" />
</shape>
</rotate>
</item>
The rotate drawable http://developer.android.com/reference/android/graphics/drawable/RotateDrawable.html
actually uses the Property Animation format http://developer.android.com/guide/topics/resources/animation-resource.html
Whereas you are making a non-animating diagonal line, you want it to start out at 45 degrees, and end up at 45 degrees also. So setting them both to 45 is the norm.
这篇关于如何旋转线的Android XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!