Is it possible to swap XML layouts during runtime in Android? -
Is it possible to load my main.xml layout file in onCreate () and later in the app, switch to a new one XML layout? I tried to put the set contentview () in the app later but in fact the new view is not being set, because the new set is returning as zero in my reference of the objects in the XML layout file, I use LayoutInflater Have tried to increase some layouts, but I have no luck (I'm probably doing something wrong) ...
Then there is no need to swap layout xml layouts on runtime Other way? Thanks!
You can have your layouts in the same xml file that you do not want to see immediately, in XML Set up android: visibility = "gone"
, and you will call hiddenView.setVisibility (see Vijayan) on runtime. ;
.
Your XML will look something like this:
& lt; Relative layout xmlns: android = "http://schemas.android.com/apk/Native/Android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" & gt; & Lt; LinearLayout Android: id = "@ + id / layout1" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" & gt; & Lt; / LinearLayout & gt; & Lt; LinearLayout Android: ID = "@ + ID / Layout 2" Android: Visibility = "gone" Android: layout_width = "filled_part" Android: layout_height = "fill_parent" & gt; & Lt; / LinearLayout & gt; & Lt; / RelativeLayout & gt;
At the runtime you can do this:
layout 1.set visibility (see gene); Layout2.setVisibility (View.VISIBLE);
This will essentially form a layout swapping.
I believe that this will also work if you have shared objects between two layouts just to make sure that you enter the ID for the first time android: id = "@ + id / view1"
and using the next setting of this ID, you can android: id = "@ id / view1"
(without +).
& lt; Relative layout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_heat = "fill_perrent" & gt; & Lt; LinearLayout Android: id = "@ + id / layout1" Android: layout_width = "fill_parent" & gt; & Lt; View Android: id = "@ + ID / View 1" /> & Lt; / LinearLayout & gt; & Lt; LinearLayout Android: id = "@ + id / layout2" Android: Visibility = "gone" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" & gt; & Lt; View Android: id = "@ id / view1" /> & Lt; / LinearLayout & gt; & Lt; / RelativeLayout & gt;
Comments
Post a Comment