我正在学习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>
主要活动.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;
}
}
}
请帮我找到解决方案。
答案 0 :(得分:5)
您正在使用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:应用=&#34; HTTP://schemas.android.com/apk/res-auto"
重要强>
你得到的东西似乎只是一个lint错误 忽略。我尝试过并遇到同样的错误,但它确实有效 正确。for more info
快乐编码:)
答案 1 :(得分:2)
这个问题只用了不到1个小时的时间-下载并尝试使用其他模拟器并进行检查。尝试了上述提示后,这就是我的解决方法!