java - 图片未加载

标签 java android imageview

我想知道为什么这里的图像根本无法加载。 XML 文件不显示图像,但显示 TextViewButton

请帮忙。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="177dp"
        android:layout_height="wrap_content"
        android:text="Middle Right Pop Up" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

    <ImageView
        android:id="@+id/small_circle"
        android:layout_width="180dp"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/small_compass" />

</LinearLayout>

public class PopUpMiddleRight extends Activity{

    ImageView compass;
    private float currentDegree = 0f;
    private static SensorManager sensorService;
    private Sensor sensor;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_pop_up_middle_right);

        WindowManager.LayoutParams windowManager = 
getWindow().getAttributes();
        windowManager.dimAmount = 0.75f;

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);

        int width = dm.widthPixels;
        int height = dm.heightPixels;

        getWindow().setLayout((int)(width * .8), (int)(height * .6));

    }

}

我正在尝试制作一个弹出窗口,因此它看起来像这样:PopUpWindow

另请注意,我在代码中的另一个位置引用了该图像,因此它可以读取该图像。

最佳答案

替换 将 app:srcCompat="@drawable/small_compass" 改为 android:src="@drawable/small_compass"

关于java - 图片未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47658199/

相关文章:

java - Stream方式获取第一个元素匹配 boolean 值的索引

java - 动态scaleType = centerCrop

java - 动态弹出菜单 Android Studio

java - mvn 测试 java.lang.OutOfMemoryError : unable to create new native thread

java - 使用 insertTab() 插入选项卡时 JTabbedPane.getComponentAt() 似乎返回错误的组件

java - 请帮我解决这个JAVA异常

android - Flutter 中的 SharedPreferences 错误

android - 回收 ui 元素

javascript - 在没有互联网连接不可用时提供自定义通知

android - 使用 Glide 显示 GIF 文件(图像加载和缓存库)