I don't know of any XML property that cannot be set via the Java API. 2009/6/24 Pavel Lahoda <plah...@gmail.com>: > > Romain, > > I have a same question as John ? How can I access some properties > (such as here in RelativeView, but there are plenty of others) through > the Java API ? It seems that some properties are only possible to set > when constructing the view from the XML : this is pretty strange. Can > you comment on that ? Thanks. > > Pavel > > > > On 17 čvn, 19:03, Romain Guy <romain...@google.com> wrote: >> You did not give an id to imageView1, so imageView1.getId() returns an >> invalid id. >> >> >> >> >> >> On Tue, Jun 16, 2009 at 4:20 PM, JohnJYates <johnjya...@gmail.com> wrote: >> >> > 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? >> >> -- >> Romain Guy >> Android framework engineer >> romain...@android.com >> >> Note: please don't send private questions to me, as I don't have time to >> provide private support. All such questions should be posted on public >> forums, where I and others can see and answer them > > > >
-- Romain Guy Android framework engineer romain...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---