我在android studio 2.3.1中创建游戏,第一个屏幕是开始屏幕。当用户触摸开始屏幕时,他们假设进入游戏场景。图像被视为背景,但保存为Imageview。我一直试图找到帮助,但我没有收到它,我不知道从哪里开始。这就是我所要求的帮助。
activity_start:
<?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"
tools:context="com.example.user.app.StartActivity"
>
<ImageView
android:id="@+id/start"
android:layout_width="600dp"
android:layout_height="380dp"
android:layout_marginBottom="-10dp"
android:layout_marginRight="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.444"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="@drawable/start" />
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:0)
答案 1 :(得分:0)
如果将图像设置为布局的背景属性,则最好不要将imageView作为屏幕的背景。在您将imageView保留为背景的情况下,可能会导致屏幕大小不同的设备出现问题。
<?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:id="+@id/start"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.user.app.StartActivity"
android:background="@drawable/start"
>
.....
</android.support.constraint.ConstraintLayout>
在您的Java代码中
public void onCreate(Bundle savedInstanceState)
{
....
ConstraintLayout startScreen = (ConstraintLayout)findViewByID(R.id.start)
startScreen.setOnClickListener(this);
}
public void onClick(View v) {
startGame();
}