Android Widget ImageView无法显示

CbL*_*CbL 3 android android-widget android-layout

我只是启动一个小部件,它的xml在AS上的模拟器中显示imageview,但无论我把imageview放在图像未显示的位置.这是我的小部件的xml布局

<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>
Run Code Online (Sandbox Code Playgroud)

模拟器

在测试电话上

即使我使用硬代码dp或其他选项放入linearlayout或relativelayout内部,甚至可以使用应用程序内部的其他项目图片进行更改,但没有显示任何内容.我只是想知道它不显示的原因是什么.

小智 6

我找到了另外一个选择.您可以设置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"/>
Run Code Online (Sandbox Code Playgroud)


arj*_*jun 1

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">
Run Code Online (Sandbox Code Playgroud)