2015-02-23 57 views
2
<?xml version="1.0" encoding="utf-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:visible="true" 
    android:shape="line"> 

<stroke 
     android:width="1dp" 
     android:color="#008000" 
     android:dashWidth="2dp" 
     android:dashGap="2dp"/> 


</shape> 

#horizo​​ntal_line.xml垂直線不垂直擴張[機器人形狀]

<?xml version="1.0" encoding="utf-8"?> 
<rotate 
    android:fromDegrees="90" 
    android:toDegrees="90" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:drawable="@drawable/horizontal_line" 
    > 

</rotate> 

#above是垂直線XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/dark_red_color"> 


<View 
     android:layout_width="50dp" 
     android:layout_height="310dp" 
     android:background="@drawable/vertical_line" 
     > 

</View> 
</LinearLayout> 

我試圖用垂直線的以上佈局或視圖。但垂直線不完全展開到其高度。

回答

1

相反的shape你可以使用這個

<View 
android:layout_width="1dp" 
android:layout_height="fill_parent" 
android:background="#FF0000FF" 
android:rotation="90" 
android:background="@android:color/darker_gray"/> 

或者,如果你想與Shape,而不是使用line使用,您可以使用rectangle這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" > 
<stroke android:width="1dp" android:color="@color/red"/> 
<size android:width="2dp" android:height="290dp" /> 
</shape> 

編輯

你必須替換這個舊的形狀,一個d我認爲它會工作:)

<?xml version="1.0" encoding="utf-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
      android:shape="rectangle"> 
    <stroke 
     android:width="1dp" 
     android:dashWidth="10px" 
     android:dashGap="10px" 
     android:rotation="90" 
     /> 
    </shape> 
+0

我想要的虛線......傳播vertically.With簡單的顏色作爲背景/繪製它可以achieved.But它不會產生虛線。 – jily 2015-02-26 10:23:56

+0

@jily查看我的編輯:) – 2015-02-26 11:12:32

+0

通過縮小矩形的寬度...矩形的左右線重疊,所以沒有實現完美的垂直虛線。 – jily 2015-02-26 15:01:19