Android Widget ImageView not show
Asked Answered
L

5

6

I just start a widget and its xml show the imageview in the emulator on AS, but whatever i put the imageview at what position the image is not show. Here is my xml layout of widget

<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

Even I put inside the linearlayout or relativelayout with hard code dp or other options and even change with other project picture which is ok inside the app, nothing showed. I just wonder what is the reason of it not show.

Lulita answered 26/2, 2017 at 14:3 Comment(0)
A
10

I found one more option. You can set background of the ImageView to show your drawable instead of setting 'src'. Again, still not very good solution, however drawable is visible.

<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"/>
Antonetteantoni answered 18/4, 2017 at 16:9 Comment(1)
What I did to make it work is to use a FrameLayout and android:background property instead of ImageView. Same thing I guess...Amenra
A
3

Try using android:src instead of app:srcCompat. I don't know if it is the best solution, but it works for me.

<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"/>
Antonetteantoni answered 3/4, 2017 at 16:26 Comment(1)
Thx for the reply. I tried to change all imageview with src , but still not work in the widget. I find this is work on the activity, but change to widget, it is still blankLulita
I
3

Use

android:src="@drawable/ic_media_next"

instead of

app:srcCompat="@android:drawable/ic_media_next"
Immovable answered 27/7, 2021 at 7:26 Comment(0)
C
1

LinearLayout will be drawn above the ImageView so it is not visible.

Try to set LinearLayout below 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">
Claytonclaytonia answered 26/2, 2017 at 14:44 Comment(1)
sorry for the late reply, I tried this way, it still have not render anything.Lulita
E
0

In my case the image wasn't shown on the widget when image's drawable contained a theme-dependent color, for example:

android:fillColor="?attr/themeColorBase80"

Check, maybe your drawables drawable/ic_popup_sync and drawable/ic_media_next contain any attributes defined implicitly, with other attributes.

If so, use explicitly defined attributes, for example:

android:fillColor="#D5D5D5"

Or check any other attributes, not only color.

Epp answered 4/6, 2021 at 21:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.