2016-02-24 122 views
0

正在虚线创建垂直线。放置View/ImageView宽度5dp或一些东西和宽度100dp,并与此不显示垂直虚线。如果我放置100dp高度和100dp宽度然后它显示虚线。所以它占用99dp空白Android - 虚线垂直线的可绘制宽度

我需要2DP或5DP宽度和高度100dp虚线

enter image description here

这里是我的代码:

dash_line.xml

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

     <stroke 
      android:color="@color/white" 
      android:dashWidth="10px" 
      android:dashGap="10px" 
      android:width="1dp"/> 
     <size android:height="300dp" /> 
    </shape> 
</rotate> 

and

破折号+空间非常小的图像
<ImageView 
    android:id="@+id/imageview" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_marginTop="100dp" 
    android:src="@drawable/dash_line" 
    android:layout_gravity="center_horizontal" /> 

回答

1

采取图片(可以重复图片)这样的,

repeat_background.xml(在绘制对象文件夹)

<?xml version="1.0" encoding="utf-8"?> 
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/bg_repeat_image" 
    android:tileMode="repeat" /> 

现在,

<ImageView 
    android:id="@+id/imageview" 
    android:layout_width="wrap_content" 
    android:layout_height="100dp" 
    android:src="@drawable/repeat_background" 
    android:layout_gravity="center_horizontal" /> 

OR

<View 
     android:id="@+id/imageview" 
     android:layout_width="wrap_content" 
     android:layout_height="100dp" 
     android:background="@drawable/repeat_background" 
     android:layout_gravity="center_horizontal" /> 

所以,你可以通过一些不同的方式,但很好的有效的方式做到这一点!

希望它能帮助你!

+0

其不重复的位图 – srinu

+0

尝试编辑答案与视图!并让我知道它是否会有所帮助! – Rahul

+0

是完美的,它与查看 – srinu