2017-02-26 70 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"/>