【问题标题】:Can't draw a line?不能画线?
【发布时间】:2016-03-27 07:15:50
【问题描述】:

我想画一条线作为ImageView's背景。但是它不起作用?

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
    <solid android:color="#FF0000FF" />
    <size android:width="10dp"
        android:height="2dp"/>
</shape>

只是一个演示。

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/dividing_line"
    android:layout_marginLeft="10dp" />

【问题讨论】:

  • 向我们展示您的布局 xml!
  • @NikoYuwono 你可以看我的布局演示
  • 尝试将宽度改为 10dp 而不是 wrap_contentn
  • @Egos 显示输出你想要的内容
  • @EgosZhang 之后您是否将图像设置到 ImageView?

标签: android android-drawable android-shapedrawable


【解决方案1】:

ImageView 没有内容,因此大小将为 0x0dp。如果您想要一个分隔线,请尝试将width 设置为match_parent,并将height 设置为您觉得合适的任何值(例如2dp)。

更新:试试这个。

在您的布局文件中:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="4dp"
    android:background="@drawable/dividing_line"
    android:layout_marginLeft="10dp" />

可绘制对象:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
    <stroke android:width="2dp" android:color="#0000FF"/>
    <size android:height="2dp" />
</shape>

它对我有用。


正如TheTool 所指出的,如果您只想要一个分隔线,更简单的解决方案是添加

<View android:layout_width="match_parent" 
      android:layout_height="2dp" 
      android:background="@color/yourColor" />

到你的布局文件。

【讨论】:

  • 不行。
  • 如果这个问题确实是关于分隔线的,只需将其添加到您的 xml 中:
猜你喜欢
  • 2013-05-17
  • 2016-07-29
  • 2011-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多