垂直线不垂直扩展[android形状]

时间:2015-02-23 09:02:52

标签: android layout view line

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

我试图在上面的布局或视图中使用垂直线。但是垂直线不会完全展开到它的高度。

2 个答案:

答案 0 :(得分: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>

修改

你必须为这个替换旧的形状,我认为它会起作用:)

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

答案 1 :(得分:0)

我解决了。在布局xml中使用负边距 像这样:

`<ImageView
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginLeft="-50dp"
    android:layout_marginRight="-50dp"
    android:src="@drawable/dotted_vertical_line" />`