13

私はAndroidアプリで対角線をXMLで描画しようとしていますが、動作していません。これは、単に水平線を描画します。Android XMLでどのように行を回転させますか?

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> 

答えて

31

あなたは本当にO nlyはそれを働かせるために1つの番号変更が必要でした。わずか45にfromDegreesを変更します。

<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> 

を回転描画可能http://developer.android.com/reference/android/graphics/drawable/RotateDrawable.html

実際http://developer.android.com/guide/topics/resources/animation-resource.htmlあなたは非アニメーション対角線を作っているのに対し

が、あなたはそれが出始めたいプロパティアニメーションの形式を使用しています45度で終わり、45度で終わる。だから両方に45を設定するのが普通です。

+0

ありがとうございました、私はfromDegreesがで意味と思いましたポイント0とtoDegreesはポイント "n"のものでした。私はそれがアニメーションに言及したことを知らなかった。 –

+0

直感的ではありません。私は助けてうれしいです。 – HalR

+1

こんにちは私は同じことが欲しかったし、それは 'android:tileMode =" repeat "'のように繰り返されるでしょうか? –

0

あなたはこれを試すことができます: レイアウト "divider.xml" を作成します

<?xml version="1.0" encoding="utf-8"?> 
<View android:layout_width="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="@dimen/one_dp" 
    android:layout_weight=".1" 
    android:background="@drawable/transparent_divider" 
    android:padding="5dp" 
    android:rotation="180"/> 

描画可能形状 "transparent_divider.xml" を作成します。

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <size android:height="1dp" /> 
    <solid android:color="#808080" /> 
</shape> 
関連する問題