gpt4 book ai didi

java - Android Studio 中的 ImageButton 问题

转载 作者:行者123 更新时间:2023-12-02 09:03:18 26 4
gpt4 key购买 nike

我尝试在 Activity 中创建两个 ImageButton,但我只能看到其中一个。有人可以帮助我吗?

activity_ristorante.xml :


?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Ristoranti">

<ImageButton
android:id="@+id/b2"
style="@style/Widget.AppCompat.ImageButton"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart="232dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="30dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/b1"
style="@style/Widget.AppCompat.ImageButton"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart="30dp"
android:layout_marginTop="50dp"
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

类(class):

public class Ristoranti extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

ImageButton b1 = findViewById(R.id.b1);
ImageButton b2 = findViewById(R.id.b2);

b1.setBackgroundResource(R.drawable.putia) ;
b2.setBackgroundResource(R.drawable.pos);


b1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
Uri uri = Uri.parse("https://maps.app.goo.gl/FoRGA2CbJdrV5cfT8");
Intent in = new Intent(Intent.ACTION_VIEW, uri);
startActivity(in);
}
});

有什么错误吗?即使在 android studio 中将其设置为“可见”,我也看不到该按钮,你能帮我吗?谢谢

最佳答案

只需将 setContentView(R.layout.activity_main); 更改为 setContentView(R.layout.activity_ristorante); 或从 activity_ristorante.xml 复制 XML 代码activity_main.xml

关于java - Android Studio 中的 ImageButton 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60012651/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com