Android Studio图片显示在设计视图中,但不显示在模拟器中
我正在学习android应用程序开发.因此,当我构建一个简单的应用程序以在屏幕上显示两个图像时,我使用了ImageView.这些图像显示在android studio设计屏幕中,但是当我尝试运行使用genymotion模拟器的应用程序,屏幕只是空白.我看不到图像.这是xml文件.
I am learning android app development.So while I was building a simple app to show two images on the screen,I have used ImageView.The images are displayed in the android studio design screen,but when I am trying to run the app using the genymotion emulator,the screen is just blank.I am not able to see the images.here is the xml file.
<?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>
主要活动.JAVA
MAIN ACTIVITY.JAVA
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;
}
}
}
请帮助我找到解决方案.
Please Help me in finding me the solution.
您正在使用srcCompat而不是src,就像使用back goku而不是goku
You are using srcCompat instead of using src just like using back goku instead of 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 库中定义的.
as it srcCompat attribute is actually defined within AppCompat library.
重要,您需要为此添加适当的名称空间.
Important you will need to add appropriate namespace for this.
xmlns:app ="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
重要
您所得到的似乎只是一个皮棉错误,可能是 忽略了.我试过了并且有同样的错误,但是它正在工作 正确.了解更多信息
what you are getting it seems like it is just a lint error that can be ignored. I have tried and have the same error, but it is working correctly.for more info
快乐编码:)