Tuesday, March 5, 2013

Re: [android-developers] How rotate a line in Android XML?

The answer is to also make fromDegrees="45". I thought from/toDegrees referred to point 0 and point "n" of the line, but it refers to animation. The rotate XML node is an animation. So you're telling it to move it from 45 degrees to 45 degrees (there's no other way to rotate a line in XML layout). Just set the duration of the animation to 0.




From: don rhummy <donrhummy@yahoo.com>
To: Android Developers <android-developers@googlegroups.com>
Sent: Tuesday, March 5, 2013 8:56 PM
Subject: [android-developers] How rotate a line in Android XML?

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 received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


No comments:

Post a Comment