Android Studio图片显示在设计视图中,但不显示在模拟器中

赛桑卡普

我正在学习android应用程序开发。因此,当我构建一个简单的应用程序以在屏幕上显示两个图像时,我使用了ImageView。这些图像显示在android studio设计屏幕中,但是当我尝试使用genymotion模拟器,屏幕只是空白。我看不到图像。这是xml文件。

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="showmebioapp.studio.com.showmebio.MainActivity"
    android:background="@android:color/holo_blue_bright">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/vegeta"
        android:layout_marginTop="32dp"
        android:id="@+id/imageVegetaId"
        android:layout_alignParentTop="true"
        android:layout_alignRight="@+id/imageGokuId"
        android:layout_alignEnd="@+id/imageGokuId"
        android:layout_marginRight="32dp"
        android:layout_marginEnd="32dp" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/goku"
        android:layout_marginBottom="79dp"
        android:id="@+id/imageGokuId"
        android:layout_marginLeft="62dp"
        android:layout_marginStart="62dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>

主要活动

public class MainActivity extends Activity implements View.OnClickListener {

private ImageView vegetaImage;
private ImageView gokuImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    vegetaImage=(ImageView)findViewById(R.id.imageVegetaId);
    gokuImage=(ImageView)findViewById(R.id.imageGokuId);
    vegetaImage.setOnClickListener(this);
    gokuImage.setOnClickListener(this);
}

@Override
public void onClick(View v) {

    switch(v.getId()){

        case R.id.imageVegetaId:
            Intent vegetaIntent=new Intent(MainActivity.this,DetailsActivity.class);
            vegetaIntent.putExtra("vegetaBio","hello from vegeta");
            startActivity(vegetaIntent);
            break;
        case R.id.imageGokuId:
            Intent gokuIntent=new Intent(MainActivity.this,DetailsActivity.class);
            gokuIntent.putExtra("gokuBio","hello from goku");
            startActivity(gokuIntent);
            break;
    }
}

}

在此处输入图片说明 在此处输入图片说明

请帮助我找到解决方案。

尼莱·斯里瓦斯塔瓦(Neelay Srivastava)

您正在使用srcCompat而不是src,就像使用back goku而不是goku

  <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:src="@drawable/vegeta"
    android:layout_marginTop="32dp"
    android:id="@+id/imageVegetaId"
    android:layout_alignParentTop="true"
    android:layout_alignRight="@+id/imageGokuId"
    android:layout_alignEnd="@+id/imageGokuId"
    android:layout_marginRight="32dp"
    android:layout_marginEnd="32dp" />

因为srcCompat属性实际上是在AppCompat库中定义的

重要的是,您需要为此添加适当的名称空间。

xmlns:app =“ http://schemas.android.com/apk/res-auto”

重要

您得到的结果似乎只是可以忽略的皮棉错误。我已经尝试过并遇到相同的错误,但是它工作正常。了解更多信息

快乐的编码:)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何旋转Android模拟器的显示?

SD卡(在AVD中创建)在Android Studio的模拟器中显示为“已删除”

Visual Studio Android模拟器显示键盘

Android ImageView在模拟器上显示,但不在设备上显示

Android Studio加载但不显示

Android Studio-TextView未在设计视图布局中显示

下载的图片显示在android studio中,但不显示在图库中

Android Studio模拟器阻止我的应用显示

在“适用于Android的Visual Studio模拟器”中启动后,Visual Studio 2019为什么不显示该模拟器?

Android Studio-imageView在设计编辑器中显示图像,但不在模拟器或设备上显示

项目列表布局显示在Android Studio中,但不在模拟器中显示

由netbeans运行时,android模拟器什么也不显示

在Android中,将文件安装到模拟器后不显示应用程序。(从本地硬盘驱动器到仿真器)

Android Webview在模拟器中显示错误

Android模拟器显示在Linux中不起作用

按钮未在Android设备中显示,但显示在电晕模拟器和mobogini中

Android Studio中的模拟器

Android Admob未在模拟器中显示为空白

模拟器未显示在Android Studio中

为什么Android Studio 2在设计中不显示布局

Android Studio Emulator 不显示设计的布局

android studio 视图未在设计模式中显示

相对布局在 Android Studio 中不起作用始终在设计视图中显示约束布局

Android 模拟器中未显示热重载更改

文本视图未显示在滚动视图中,在 Android 模拟器中

Android 模拟器在 Android Studio 中启动,但未显示在设备选项卡中

为什么在横向视图中旋转时 Android Studio 模拟器是颠倒的?

Android Studio 在模拟器中显示不同的设计

拖到 Android 模拟器的图像未显示在图库中