我使用此代码扩充我的布局:
FrameLayout frameLayout = findViewById(R.id.activity_frame);
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View activityView5 = layoutInflater.inflate(activity_start_home, null, false);
frameLayout.addView(activityView5);
我膨胀的XML-Layout看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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.musictrainer.music_trainer.StartHome">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/background"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_start_home" />
</android.support.design.widget.CoordinatorLayout>
此布局中包含的“内容”如下所示:
<?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:background="@color/background"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.musictrainer.music_trainer.StartHome"
tools:layout_editor_absoluteY="81dp"
tools:showIn="@layout/activity_start_home">
<Button
android:id="@+id/inton_but"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="92dp"
android:background="@color/buttons"
android:text="Intonation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/tuner_but"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="64dp"
android:background="@color/buttons"
android:text="Tuner"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/inton_but" />
</android.support.constraint.ConstraintLayout>
因此,当我给布局充气时,它会显示布局,但按钮不起作用。我是否还需要给按钮充气?我是否需要夸大内容?
答案 0 :(得分:0)
如果您根据导航项更改布局,我建议您使用片段