Moving widgets in runtime on Android -


I have a simple demo with two buttons, they are placed in the upper and lower part of the screen with a relative layout. .
When I click on one of them, I want to switch them to locations. What is the best way to do this?

This is my rage / layout / main. Xml is:

  & lt ;? Xml version = "1.0" encoding = "UTF-8" & gt; & Lt; RelativeLayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" & gt; Android: layout_alignParentTop = "true" /> & Lt; Image button Android: Android: layout_width = "200dp" Android: layout_heat = "wrap-content" Android: Android: Android: layout_alignParentBottom = "true" /> & Lt; ImageButton Android: Android: layout_width = "200dp" Android: layout_height = "wrap_content" Android: src = "@drawable / icon 2" & lt; / RelativeLayout & gt;  

And this is my activity:

  Expands the public class HelloButtons activity {/ ** is called when activity is created first / @ Override Crate on Public Zero (Bundle Saved Instantstate) {Super. Contents (Saved Instantstate); SetContentView (R.layout.main); Final Image Button Button 1 = (Image Button) Find VVBIID (R.D.Dandroid_Buttony); Final Image Button Button 2 = (Image Button) Find VVBIID (R.D.Dr.OrDrude_Button_O); Show Button1.setOnClickListener (New OnClickListener) {public void onClick (see v) {// click on actions. Toast.Mektext ("Hello", "beep bop", toast.LnnGHIHT) Show ();}}); Show Button2.setOnClickListener (New OnClickListener) {public void onClick (see v) {// click on actions. Toast.Mektext ("Hello", "Bip Bop", Toast. LNNHHARART) Show ();}}); }}  

Use something with these lines

  RelativeLayout.LayoutParams lp1 = (Layout Parameters) B 1.getLayoutParams (); Relative layout. LayoutParas lp2 = (Layout Parameters) B 2.getLayoutParams (); Lp2.addRule (relative layout .ALIGN_PARENT_BOTTOM, relative layout. TRUE); Lp2.addRule (relative layout. ALIGN_PARENT_TOP, 0); Lp1.addRule (relative layout .ALIGN_PARENT_TOP, relative layout. TRUE); Lp1.addRule (relative layout. ALIGN_PARENT_BOTTOM, 0); B1.setLayoutParams (LP1); B2.setLayoutParams (lp2); You  OnClickListeners  

in

(and revert to them again)

Comments

Popular posts from this blog

php - multilevel menu with multilevel array -

c# - TypeConverter in propertygrid only converts from string, not to -

jQuery UI: Datepicker month format -