我是Android Studio的新手,正在为活动创建应用程序。我有主页,带有ImageButton的页面将打开一个新活动-事件信息,其中包含文本和按钮。该应用程序具有底部导航,一旦打开“事件信息”,每次我单击底部导航上的按钮时,它都会打开所需的活动,但是“事件位置”中的按钮位于新活动的顶部。我不能单击所需活动上的任何内容,仅可以单击似乎保留在所有活动顶部的按钮。我没有收到任何关于此的错误,也不知道如何解决。
这是“事件信息”页面的Java代码:
public class EventInformation extends AppCompatActivity {
Button eventLocationButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_event_information);
mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(navigationListener);
eventLocationButton = findViewById(R.id.btn_EventLocation);
eventLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent openEventInformation = new Intent(EventInformation.this, Location.class);
startActivity(openEventInformation);
}
});
}
public void setEvent(String event) {
this.event = event;
BottomNavigationView bottomNavigationView = findViewById(R.id.navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(navigationListener);
}
private BottomNavigationView.OnNavigationItemSelectedListener navigationListener =
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment selectedFragment = null;
switch (item.getItemId()){
case R.id.navigation_home:
selectedFragment = new HomeFragment();
break;
case R.id.navigation_contactInformation:
selectedFragment = new ContactFragment();
break;
case R.id.navigation_location:
selectedFragment = new LocationFragment();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.container,
selectedFragment).commit();
return true;
}
};
}
EventInformation布局文件:
<?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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context="com.example.u1854455.kimmisquickbook.EventInformation">
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginStart="8dp"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:text="Event Inofmation"
android:textColor="@android:color/white"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#000000"
app:itemIconTint="@color/backgroundBlue"
app:itemTextColor="@color/backgroundBlue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
<TextView
android:id="@+id/textView17"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginTop="8dp"
android:text="The event you have chosen is: "
android:textColor="@android:color/white"
app:layout_constraintTop_toBottomOf="@+id/message"
tools:layout_editor_absoluteX="16dp"
tools:ignore="MissingConstraints" />
<TextView
android:id="@+id/lb_Artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Name: Drake"
android:textColor="@android:color/white"
android:textSize="18sp"
app:layout_constraintTop_toBottomOf="@+id/textView17"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="87dp" />
<TextView
android:id="@+id/lb_Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Date: 5th October 2019"
android:textColor="@android:color/white"
android:textSize="18sp"
app:layout_constraintTop_toBottomOf="@+id/lb_Artist"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="87dp" />
<TextView
android:id="@+id/lb_Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Start tiime: 19:30"
android:textColor="@android:color/white"
android:textSize="18sp"
app:layout_constraintTop_toBottomOf="@+id/lb_Date"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="87dp" />
<TextView
android:id="@+id/lb_City"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="End time: Late"
android:textColor="@android:color/white"
android:textSize="18sp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="87dp"
tools:layout_editor_absoluteY="255dp" />
<TextView
android:id="@+id/lb_Location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Location: First Direct Arena, Leeds"
android:textColor="@android:color/white"
android:textSize="18sp"
app:layout_constraintTop_toBottomOf="@+id/lb_City"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="87dp" />
<Button
android:id="@+id/btn_EventLocation"
android:layout_width="154dp"
android:layout_height="37dp"
android:text="Event Location"
app:layout_constraintStart_toStartOf="@+id/lb_Location"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteY="372dp" />
</android.support.constraint.ConstraintLayout>
位置布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>