Wie kann ich ein Layout zu einem anderen Layout hinzufügen?So fügen Sie ein Layout zu einem anderen Layout in Android hinzu
Wie kann ein in Java geschriebenes Layout zu einem anderen Layout hinzugefügt werden. In diesem Fall möchte ich new RevAppBarLayout().getRevAppBarLayout(this);
zu einem DrawerLayout namens Schublade hinzufügen.
DrawerLayout drawer = new DrawerLayout(this);
drawer.addView(inflatedLayout);
public class RevAppBarLayout extends MainActivity {
public AppBarLayout getRevAppBarLayout(Context context) {
AppBarLayout revAppBarLayout = new AppBarLayout(context);
Toolbar revToolBar = new Toolbar(context);
setSupportActionBar(revToolBar);
return revAppBarLayout;
}
}
Dies ist, wie es zu tun ist, wenn es sich um ein XML-Fragment waren:
AppBarLayout revAppBarLayout = new RevToolBar().getRevAppBarLayout(this);
LayoutInflater inflater = LayoutInflater.from(context);
View inflatedLayout= inflater.inflate(R.layout.yourLayout, null, false);
drawer.addView(inflatedLayout);
Warum ist ein Fragment wichtig? 'View.addView' ist die Methode, und Sie scheinen sie bereits zu benutzen –