If a RelativeLayout must be generated at run time, what are the
equivalent API calls for the attributes set in the XML Layout editor?
Take for example this very simple RelativeLayout that places the
second ImageView to the right of the first ImageView:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="horizontal" android:background="@drawable/
bg_sunrise" android:layout_gravity="center" android:gravity="center">

<ImageView android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/icon"></
ImageView>

<ImageView android:id="@+id/ImageView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toRightOf="@id/
ImageView01" android:src="@drawable/icon"></ImageView>
</RelativeLayout>


Of the many, many, many, many variations I tried, I had the most hope
for this one, but it didn't work either:

       protected void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
               this.requestWindowFeature(Window.FEATURE_NO_TITLE);
               RelativeLayout layout = new RelativeLayout(this);
               layout.setLayoutParams( new
                               ViewGroup.LayoutParams
( LayoutParams.FILL_PARENT,
                               LayoutParams.FILL_PARENT ) );

           ImageView imageView1 = new ImageView(this);
           imageView1.setImageResource(R.drawable.icon);
           imageView1.setAdjustViewBounds(true); // set the ImageView
bounds
to match the Drawable's dimensions

               RelativeLayout.LayoutParams params1 = new
RelativeLayout.LayoutParams
(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
               params1.addRule(RelativeLayout.ALIGN_PARENT_TOP);
           layout.addView(imageView1, params1);

           ImageView imageView2 = new ImageView(this);
           imageView2.setImageResource(R.drawable.icon);
           imageView2.setAdjustViewBounds(true); // set the ImageView
bounds
to match the Drawable's dimensions

               RelativeLayout.LayoutParams params2 = new
RelativeLayout.LayoutParams
(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
               params2.addRule(RelativeLayout.RIGHT_OF,
imageView1.getId());
           layout.addView(imageView2, params2);
           this.setContentView(layout);
       }

Can anyone offer the Java equivalent to the above XML?  Can anyone
explain why there is no attribute, getter/setter, or method for
accessing the properties that can be set in XML?  What is the most
elegant solution for dynamically creating Layouts, Views, and other
Resources on the Android platform when there is no Java programmatic
equivalent?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to