在我的设计视图中它显示了屏幕上的两个图像,但是在模拟器上它没有显示它们中的任何一个,我对此全新,并试图使它们可见无效,所以任何指导正确的方向将是美好的。
继承了该程序的Java,因为我不确定这是否有用?第16行是我将内容视图设置为该设计页面的地方
问题:
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private ImageView imageThumbnail;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cell_image_card);
imageThumbnail = (ImageView) findViewById(R.id.mainImage);
imageThumbnail.setOnClickListener(itemClicked);
}
private View.OnClickListener itemClicked = new View.OnClickListener() {
@Override
public void onClick(View v) {
//when the item is clicked, go ahead and open the new activity
Intent intent = new Intent(v.getContext(), DetailsActivity.class);
startActivity(intent);
}
};
}
设计的XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/imageTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:text="@string/textview"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp" />
<ImageView
android:id="@+id/mainImage"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_marginTop="8dp"
android:scaleType="centerCrop"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageTitle"
app:srcCompat="@drawable/singapore"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/starImageBtn"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:scaleType="centerCrop"
android:tint="@android:color/darker_gray"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/shareImageBtn"
app:layout_constraintTop_toBottomOf="@+id/mainImage"
app:layout_constraintVertical_bias="0.100000024"
app:srcCompat="@drawable/ic_star"
tools:ignore="ContentDescription,RtlHardcoded" />
<ImageView
android:id="@+id/shareImageBtn"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:contentDescription=""
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mainImage"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="@drawable/ic_share"
tools:ignore="ContentDescription,RtlHardcoded"
tools:tint="@android:color/darker_gray" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
任何指导都会受到赞赏,因为我已经尝试了一个小时才能完成这项工作
答案 0 :(得分:0)
尝试使用android:src:imageName
代替app:srcCompat
....有时它可以将srcCompat更改为android:src ...但不要问我为什么......我有一个改变值得的项目