英文:
Button closing the app instead of switching activity
问题
Main Activity:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button play = (Button)findViewById(R.id.play);
Button quit = (Button)findViewById(R.id.quit);
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openGame();
}
});
quit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
quitGame();
}
});
}
void openGame() {
Intent intent = new Intent(MainActivity.this, Game.class);
startActivity(intent);
}
void quitGame() {
finish();
System.exit(0);
}
}
Game Activity:
public class Game extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
final ConstraintLayout constraintLayout = (ConstraintLayout)findViewById(R.id.bg);
constraintLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
String color1[] = {"#fb5959", "#fe7738", "#f3980b", "#DBD100", "#A8D700", "#87E50C"};
String color2[] = {"#54F370", "#00FFBC", "#00FFFF", "#00FFE9", "#00C8FF", "#0085FF"};
Random random = new Random();
GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.BL_TR,
new int[]{Color.parseColor(color1[random.nextInt(6)]), Color.parseColor(color2[random.nextInt(6)])});
constraintLayout.setBackgroundDrawable(gradientDrawable);
return false;
}
});
Button one = (Button) findViewById(R.id.one);
Button two = (Button) findViewById(R.id.two);
Button three = (Button) findViewById(R.id.three);
Button four = (Button) findViewById(R.id.four);
Button five = (Button) findViewById(R.id.five);
Button six = (Button) findViewById(R.id.six);
Button seven = (Button) findViewById(R.id.seven);
Button eight = (Button) findViewById(R.id.eight);
Button nine = (Button) findViewById(R.id.nine);
}
}
Game Activity XML:
<androidx.constraintlayout.widget.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/bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0D95DF"
tools:context=".Game">
<!-- Buttons one through nine -->
<Button
android:id="@+id/one"
android:layout_width="91dp"
android:layout_height="90dp"
android:background="?android:attr/selectable"
android:text="?"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintHorizontal_bias="0.015"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.029" />
<!-- ... More button elements ... -->
<!-- Player labels and input fields -->
<TextView
android:id="@+id/player1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Player 1 (X) :"
android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.177"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.098" />
<!-- ... More player input fields ... -->
<!-- Guidelines for layout positioning -->
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="20dp"
app:layout_constraintGuide_percent="0.3" />
<!-- ... More guidelines ... -->
<!-- Divider lines for the game board -->
<View
android:id="@+id/vertical1"
android:layout_width="4dp"
android:layout_height="282dp"
android:background="?android:attr/listDivider"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintHorizontal_bias="0.333"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.5"
tools:visibility="visible" />
<!-- ... More divider lines ... -->
</androidx.constraintlayout.widget.ConstraintLayout>
Stack Trace (Error message indicating issues with inflating Button and attributes):
05/05 13:14:41: Launching 'app' on OnePlus ONE A2003.
$ adb shell am start -n "com.example.tictactoe/com.example.tictactoe.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 21369 on device 'oneplus-one_a2003-3222ee10'.
...
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class Button
...
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x10101e6 a=-1}
...
Please note that I've omitted the part of the stack trace that is not relevant to the code and translation. If you have any specific questions or need further assistance, feel free to ask.
英文:
I am trying to make a game Tic-Tac-Toe using android studio. When I try to switch from MainActivity to another activity(Game), instead of switching, the button closes the app. I have added several buttons in Game activity but have not used them and android studio is not showing any error about that so is the problem in Game activity or MainActivity? And how to solve this problem.
Main Activity:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button play = (Button)findViewById(R.id.play);
Button quit = (Button)findViewById(R.id.quit);
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openGame();
}
});
quit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
quitGame();
}
});
}
void openGame() {
Intent intent = new Intent(MainActivity.this, Game.class);
startActivity(intent);
}
void quitGame() {
finish();
System.exit(0);
}
}
Game Activity:
public class Game extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
final ConstraintLayout constraintLayout = (ConstraintLayout)findViewById(R.id.bg);
constraintLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
String color1[] = {"#fb5959", "#fe7738", "#f3980b", "#DBD100", "#A8D700", "#87E50C"};
String color2[] = {"#54F370", "#00FFBC", "#00FFFF", "#00FFE9", "#00C8FF", "#0085FF"};
Random random = new Random();
GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.BL_TR,
new int[]{Color.parseColor(color1[random.nextInt(6)]),Color.parseColor(color2[random.nextInt(6)])});
constraintLayout.setBackgroundDrawable(gradientDrawable);
return false;
}
});
Button one = (Button) findViewById(R.id.one);
Button two = (Button) findViewById(R.id.two);
Button three = (Button) findViewById(R.id.three);
Button four = (Button) findViewById(R.id.four);
Button five = (Button) findViewById(R.id.five);
Button six = (Button) findViewById(R.id.six);
Button seven = (Button) findViewById(R.id.seven);
Button eight = (Button) findViewById(R.id.eight);
Button nine = (Button) findViewById(R.id.nine);
}
}
Stack Trace:
05/05 13:14:41: Launching 'app' on OnePlus ONE A2003.
$ adb shell am start -n "com.example.tictactoe/com.example.tictactoe.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 21369 on device 'oneplus-one_a2003-3222ee10'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/Choreographer: Skipped 107 frames! The application may be doing too much work on its main thread.
E/AbstractTracker: Can't create handler inside thread that has not called Looper.prepare()
D/AppTracker: App Event: start
E/AbstractTracker: Can't create handler inside thread that has not called Looper.prepare()
D/AppTracker: App Event: stop
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.tictactoe, PID: 21369
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tictactoe/com.example.tictactoe.Game}: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2452)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535)
at android.app.ActivityThread.access$900(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:152)
at android.app.ActivityThread.main(ActivityThread.java:5497)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class Button
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.example.tictactoe.Game.onCreate(Game.java:20)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2405)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535) 
at android.app.ActivityThread.access$900(ActivityThread.java:155) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:152) 
at android.app.ActivityThread.main(ActivityThread.java:5497) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class Button
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) 
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) 
at com.example.tictactoe.Game.onCreate(Game.java:20) 
at android.app.Activity.performCreate(Activity.java:6289) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2405) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535) 
at android.app.ActivityThread.access$900(ActivityThread.java:155) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:152) 
at android.app.ActivityThread.main(ActivityThread.java:5497) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x10101e6 a=-1}
at android.content.res.TypedArray.getDrawable(TypedArray.java:867)
at android.view.View.<init>(View.java:3964)
at android.widget.TextView.<init>(TextView.java:680)
at android.widget.Button.<init>(Button.java:109)
at android.widget.Button.<init>(Button.java:105)
at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:72)
at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:68)
at androidx.appcompat.app.AppCompatViewInflater.createButton(AppCompatViewInflater.java:192)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:111)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1407)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1457)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) 
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) 
at com.example.tictactoe.Game.onCreate(Game.java:20) 
at android.app.Activity.performCreate(Activity.java:6289) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2405) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535) 
at android.app.ActivityThread.access$900(ActivityThread.java:155) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:152) 
at android.app.ActivityThread.main(ActivityThread.java:5497) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
D/AppTracker: App Event: crash
I/Process: Sending signal. PID: 21369 SIG: 9
Game Activity Xml Code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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/bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0D95DF"
tools:context=".Game">
<Button
android:id="@+id/one"
android:layout_width="91dp"
android:layout_height="90dp"
android:background="?android:attr/selectable"
android:text="\?"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintHorizontal_bias="0.015"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.029" />
<Button
android:id="@+id/two"
android:layout_width="90dp"
android:layout_height="90dp"
android:background="?android:attr/selectable"
android:text="\?"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.034" />
<Button
android:id="@+id/three"
android:layout_width="91dp"
android:layout_height="90dp"
android:background="?android:attr/selectable"
android:text="\?"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintHorizontal_bias="0.984"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.034" />
<Button
android:id="@+id/four"
android:layout_width="91dp"
android:layout_height="92dp"
android:background="?android:attr/selectable"
android:text="\?"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintHorizontal_bias="0.015"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.497" />
<Button
android:id="@+id/five"
android:layout_width="91dp"
android:layout_height="92dp"
android:background="?android:attr/selectable"
android:text="\?"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.497" />
<Button
android:id="@+id/six"
android:layout_width="91dp"
android:layout_height="92dp"
android:background="?android:attr/selectable"
android:text="\?"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintHorizontal_bias="0.984"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.497" />
<Button
android:id="@+id/seven"
android:layout_width="91dp"
android:layout_height="92dp"
android:background="?android:attr/selectable"
android:text="\?"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintHorizontal_bias="0.015"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.975" />
<Button
android:id="@+id/eight"
android:layout_width="91dp"
android:layout_height="92dp"
android:background="?android:attr/selectable"
android:text="\?"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.975" />
<Button
android:id="@+id/nine"
android:layout_width="91dp"
android:layout_height="92dp"
android:background="?android:attr/selectable"
android:text="\?"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintHorizontal_bias="0.984"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.975" />
<TextView
android:id="@+id/player1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Player 1 (X) :"
android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.177"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.098" />
<EditText
android:id="@+id/name1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName"
android:textAlignment="center"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.513"
app:layout_constraintStart_toEndOf="@+id/player1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.088" />
<TextView
android:id="@+id/player2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Player 2 (O) :"
android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.175"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.177" />
<EditText
android:id="@+id/name2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName"
android:textAlignment="center"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.513"
app:layout_constraintStart_toEndOf="@+id/player1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.17" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="20dp"
app:layout_constraintGuide_percent="0.3" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="462dp"
app:layout_constraintGuide_percent="0.7" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="20dp"
app:layout_constraintGuide_percent="0.15" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="358dp"
app:layout_constraintGuide_percent="0.85" />
<View
android:id="@+id/vertical1"
android:layout_width="4dp"
android:layout_height="282dp"
android:background="?android:attr/listDivider"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintHorizontal_bias="0.333"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.5"
tools:visibility="visible" />
<View
android:id="@+id/vertical2"
android:layout_width="4dp"
android:layout_height="282dp"
android:background="?android:attr/listDivider"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintHorizontal_bias="0.666"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.5"
tools:visibility="visible" />
<View
android:id="@+id/horizontal1"
android:layout_width="282dp"
android:layout_height="4dp"
android:background="?android:attr/listDivider"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.333" />
<View
android:id="@+id/horizontal2"
android:layout_width="282dp"
android:layout_height="4dp"
android:background="?android:attr/listDivider"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/guideline4"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/guideline1"
app:layout_constraintVertical_bias="0.666" />
</androidx.constraintlayout.widget.ConstraintLayout>
答案1
得分: 0
你遇到的是膨胀异常,Android 无法展开 Button,因为它无法识别 ?attr/...。我之前也遇到过类似的问题。尝试在 XML 中移除这行。
android:background="?android:attr/selectable"
如果问题仍然存在,移除所有带有以下内容的行。
android:.......="?attr/...."
英文:
what you have is an inflation exception, Android is unable to inflate Button because it does not recognize an ?attr/... i had a similar problem a while back. Try removing this line in xml.
android:background="?android:attr/selectable"
if problem persists remove all lines with.
android:.......="?attr/...."
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论