2017-02-26 72 views
0

我只是启动一个小部件,它的xml在AS上的模拟器中显示imageview,但无论我将imageview放在图像不显示的位置。这里是小部件的我的XML布局Android Widget ImageView不显示

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#333" 
android:padding="@dimen/widget_margin"> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:srcCompat="@android:drawable/ic_popup_sync" 
    android:id="@+id/imageView" 
    android:layout_alignParentLeft="true"/> 

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_alignLeft="@+id/imageView" 
    android:layout_alignRight="@+id/imageView2" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="10"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="4"> 

     <TextView 
      android:text="TextView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/textView2" /> 

     <TextView 
      android:text="TextView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/textView3" /> 

     <TextView 
      android:text="TextView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/textView4" /> 
    </LinearLayout> 

    <TextView 
     android:text="16:00" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/textView5" 
     android:textSize="20sp" 
     android:layout_weight="3" /> 

    <TextView 
     android:text="14:00" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:textSize="12sp" 
     android:id="@+id/textView6" 
     android:layout_weight="1" /> 

</LinearLayout> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    app:srcCompat="@android:drawable/ic_media_next" 
    android:id="@+id/imageView2" /> 
</RelativeLayout> 

emulator

on test phone

即使我把的LinearLayout或RelativeLayout的硬编码DP或其他选项里,甚至与其他项目的图片这是确定内部改变应用程序,没有显示。我只是想知道它没有显示的原因是什么。

回答

0

LinearLayout将被绘制在ImageView之上,因此它不可见。

尝试设置LinearLayout下面ImageView

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:srcCompat="@android:drawable/ic_popup_sync" 
    android:id="@+id/imageView" 
    android:layout_alignParentLeft="true"/> 

<LinearLayout 
    android:layout_below="@+id/imageView" //add this to set this layout below imageview 
    android:orientation="horizontal" 
    android:layout_alignLeft="@+id/imageView" 
    android:layout_alignRight="@+id/imageView2" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="10"> 
+0

对于迟到的回复感到抱歉,我试过这种方式,它仍然没有渲染任何东西。 – CbL

0

采用了android尝试:SRC,而不是应用程序:srcCompat。我不知道这是否是最好的解决方案,但它适用于我。

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@android:drawable/ic_popup_sync" 
    android:id="@+id/imageView" 
    android:layout_alignParentLeft="true"/> 
+0

Thx的答复。我试图用src更改所有imageview,但仍然无法在小部件中使用。我发现这是对活动的工作,但是改成小部件,它仍然是空白的 – CbL

0

我发现了另外一个选项。你可以设置ImageView的背景来显示你的drawable而不是设置'src'。再次,仍然不是很好的解决方案,但可绘制的是可见的。

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@android:drawable/ic_popup_sync" 
    android:id="@+id/imageView" 
    android:layout_alignParentLeft="true"/>