Hello again, I just wanted to add that the layout.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content">
<com.example.RPCPlayerInfoTitle android:id="@+id/player_info" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> when I changed the layout_width and layout_height to constants, the addRule works. another thing I've noticed is that when I don't override onMeasure in RPCPlayerInfoTitle, myImage is being aligned to the bottom of the screen. from some strange reason myImage doesn't recognized RPCPlayerInfoTitle (my custom View) as its parent or ignore its dimensions. thanks ayanir On Sep 15, 6:05 pm, ayanir <ayanir...@gmail.com> wrote: > Hello, > > I've tried to use the addRull but it seems it doesn't work. in fact, > when I used it the View disappeared from the screen. > here is my code: > > package com.example; > > import android.content.Context; > import android.content.res.Resources; > import android.graphics.BitmapFactory; > import android.util.AttributeSet; > import android.widget.ImageView; > import android.widget.RelativeLayout; > > public class RPCPlayerInfoTitle extends RelativeLayout > { > > private static final int VIEW_ID_IMAGE = 0; > private static final int VIEW_ID_NAME = 1; > private static final int VIEW_ID_RANK = 2; > > ImageView bg; > ImageView myImage; > > public RPCPlayerInfoTitle(Context context, AttributeSet attrs) { > super(context, attrs); > setLayoutParams(new RelativeLayout.LayoutParams > (RelativeLayout.LayoutParams.WRAP_CONTENT, > RelativeLayout.LayoutParams.WRAP_CONTENT)); > > bg = new ImageView(context); > Resources res = getResources(); > bg.setImageBitmap(BitmapFactory.decodeResource(res, > R.drawable.bg2)); > addView(bg); > > myImage = new ImageView(context); > myImage.setImageBitmap(BitmapFactory.decodeResource(res, > R.drawable.p_image)); > myImage.setId(VIEW_ID_IMAGE); > > RelativeLayout.LayoutParams param1 = new > RelativeLayout.LayoutParams > (LayoutParams.WRAP_CONTENT, > LayoutParams.WRAP_CONTENT); > > //***when I add this line the playerImage disappears > param1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); > > addView(myImage, param1); > > } > > @Override > protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) > { > super.onMeasure(widthMeasureSpec, heightMeasureSpec); > setMeasuredDimension(bg.getMeasuredWidth(), > bg.getMeasuredHeight()); > } > > } > > does anyone have a clue? > > Thanks, > ayanir > > On Aug 4, 8:46 pm, bpellow <bpello...@gmail.com> wrote: > > > I got this to work withaddruleandRelativeLayout.LayoutParams > > > // center my_textbox > > RelativeLayout.LayoutParamsparams_center = > > newRelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, > > LayoutParams.WRAP_CONTENT); > > params_center.addRule(RelativeLayout.CENTER_IN_PARENT); > > > // add my_textbox > > l.addView(my_textbox, params_center); > > > You could do this similarly with all types of dynamic view additions > > (given appropriate rules) so far as I can tell. > > > Thanks guys. > > > On Jul 30, 3:08 pm, Mark Murphy <mmur...@commonsware.com> wrote: > > > > doubleslash wrote: > > > >> Just like John and Pavel, I cannot figure out how to set some > > > >> RelativeLayout XML attributes programmatically in Java. > > > > >> For example, I cannot find a programmatic way to define > > > >> "layout_centerVertical=true" with only Java. > > > >http://developer.android.com/reference/android/widget/RelativeLayout.... > > > > -- > > > Mark Murphy (a Commons > > > Guy)http://commonsware.com|http://twitter.com/commonsguy > > > > Warescription: Three Android Books, Plus Updates, $35/Year --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---