2015-09-07 114 views
0

我想添加一个图层列表作为android中的图像视图控件的背景。无法在图像视图中显示图层列表

我曾尝试将其添加为android:background="@drawable/layer_list_xmlfile
以及还有android:src="@drawable/layer_list_xmlfile

当我添加图层列表时,预览窗口没有显示任何内容,也没有显示在构建apk上(在genymotion以及真实的Android设备上使用)。

这里就是我得到:

no idea what error icon means

层名单应该在那里的预览窗口上一个红点的位置上。

我的ImageView的布局代码:

<ImageView android:id="@+id/service_offers" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:src="@drawable/customoffertag" 
      android:scaleType="center" 
      android:contentDescription="@string/service_offer"/> 

我的层列表(customoffertag.xml):

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:id="@+id/custom_layer_item"> 
     <rotate 
      android:fromDegrees="-65" 
      android:toDegrees="45" 
      android:pivotX="-55%" 
      android:pivotY="1%" > 
      <shape 
       android:shape="rectangle" > 
       <stroke android:color="@android:color/transparent" 
        android:width="10dp"/> 
       <solid 
        android:color="#008475" /> 
      </shape> 
     </rotate> 
    </item> 
</layer-list> 

请谁能告诉我这是什么错误图标指示,或者我要去哪里错误。

全面布局代码:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_margin="2dp" 
    android:padding="5dp" > 

<android.support.v7.widget.CardView 
    android:id="@+id/card_list_service" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    card_view:cardCornerRadius="4dp" 
    android:padding="5dp" 
    android:background="#FFFFFF" 
    android:elevation="4dp"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ImageView android:id="@+id/service_pic" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_marginRight="3dp" 
      android:layout_marginEnd="3dp" 
      android:layout_centerVertical="true" 
      android:scaleType="fitXY" 
      android:contentDescription="@string/item_pic"/> 

     <TextView android:id="@+id/service_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toEndOf="@id/service_pic" 
      android:layout_toRightOf="@id/service_pic" 
      android:layout_alignTop="@id/service_pic" 
      android:padding="5dp" 
      android:gravity="center" 
      android:text="@string/service_provider_name" 
      android:textColor="#000000" 
      android:textSize="18sp" 
      android:textStyle="normal" 
      android:typeface="monospace" 
      android:layout_marginBottom="2dp"/> 

     <ImageView android:id="@+id/pickup_service" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toEndOf="@id/service_text" 
      android:layout_toRightOf="@id/service_text" 
      android:layout_alignBottom="@id/service_text" 
      android:layout_alignParentTop="true" 
      android:src="@drawable/pickup" 
      android:scaleType="centerCrop" 
      android:padding="5dp" /> 

     <ImageView android:id="@+id/service_offers" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:src="@drawable/customoffertag" 
      android:scaleType="center" 
      android:contentDescription="@string/service_offer"/> 

     <TextView android:id="@+id/service_contact_no" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/service_text" 
      android:layout_toRightOf="@id/service_pic" 
      android:layout_toEndOf="@id/service_pic" 
      android:layout_alignStart="@id/service_text" 
      android:layout_alignLeft="@id/service_text" 
      android:padding="5dp" 
      android:gravity="center" 
      android:text="@string/service_provider_contact" 
      android:textColor="#848484" 
      android:textStyle="normal" 
      android:textSize="16sp" 
      android:typeface="monospace" /> 

     <TextView android:id="@+id/service_dist" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/service_contact_no" 
      android:layout_toEndOf="@id/service_pic" 
      android:layout_toRightOf="@id/service_pic" 
      android:layout_alignLeft="@id/service_contact_no" 
      android:layout_alignStart="@id/service_contact_no" 
      android:padding="5dp" 
      android:gravity="center" 
      android:text="@string/service_provider_dist" 
      android:textColor="#848484" 
      android:textSize="15sp" 
      android:textStyle="normal" 
      android:typeface="monospace"/> 

     <Button android:id="@+id/booknow_btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/service_contact_no" 
      android:layout_toRightOf="@id/service_dist" 
      android:layout_toEndOf="@id/service_dist" 
      android:layout_alignBottom="@id/service_dist" 
      android:padding="5dp" 
      android:text="@string/booknow" 
      android:textSize="17sp" 
      android:textStyle="normal" 
      android:textColor="#FFFFFF" 
      android:typeface="monospace" 
      android:gravity="center" 
      android:background="#008475" 
      android:elevation="2dp"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:text="@string/review_2" 
      android:textColor="#848484" 
      android:textSize="17sp" 
      android:id="@+id/review_text" 
      android:layout_centerVertical="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:padding="3dp" 
      android:layout_marginEnd="3dp" 
      android:layout_marginRight="3dp" 
      android:gravity="end" /> 

     <TextView android:id="@+id/review_text1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:text="@string/review_1" 
      android:textSize="17sp" 
      android:textColor="#FFFFFF" 
      android:layout_centerVertical="true" 
      android:layout_toLeftOf="@id/review_text" 
      android:layout_toStartOf="@id/review_text" 
      android:layout_alignTop="@id/review_text" 
      android:layout_marginRight="0dp" 
      android:layout_marginEnd="0dp" 
      android:padding="3dp" 
      android:background="#424242"/> 

    </RelativeLayout> 

</android.support.v7.widget.CardView> 

+0

这不是一个错误图标。这只是customoffertag.png的预览版 –

+0

好的,那么我在做什么错误的产生红色惊叹号预览? –

+0

发布您的文件的所有xml,这可能只是一个布局问题。 –

回答

0

仅当高度和宽度未设置为wrap_content而是设置为特定尺寸时,才将图层列表显示在imageview窗口小部件中。

对于我来说,尺寸是height = 100dp;宽度= 50dp

试过同样的事情用一个简单的颜色

android:background="#000000" 

并且还与android:src="#000000"

两者将不显示任何东西,直到宽度和ImageView的高度被定义为一个特定的值DP 。

0

检查customoffertag.xml是否是可绘制的文件夹下。只有这样它才能识别文件并进一步处理。

+0

是的,它是在drawable下。 –

+0

我试过了。没有错误的drawable xml以及layout xml 。可能是它的编译问题。请清理并构建一次。 –

+0

我已经尝试了这些东西(clean&build),结果相同。 –