RelativeLayout params for main screen widget - android

What's up guys!
Here is an example of my layout xml:
<RelativeLayout
android:id="#+id/conf_RLayoutMultiSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
>
<ImageView
android:id="#+id/widget_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/transparent100" />
<ImageView
android:id="#+id/widget_scar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/scar1" />
</RelativeLayout>
<ImageView
android:id="#+id/widget_dial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/dial1" />
</RelativeLayout>
The question is - is it possible to change the conf_RLayoutMultiSize size through the code?
I have the cofigurantion layout where I did it easy, but can't realise how to do it on manescreen vidget.
I've tried this
widgetView.setInt(R.id.conf_RLayoutMultiSize,"setLayoutParams",150+widgetBodySize);
but it wasn't succesful

You can do it as follows:
RelativeLayout rlay = (RelativeLayout) findViewById(R.id.conf_RLayoutMultiSize);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(value_width, value_height); // Set whatever parameters you want here
rlay.setLayoutParams(params); // Assign parameters to relative layout

Related

How to display Relative layout content from top of the screen

I am having following layout in file mylayout.xml.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/yellow"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:id="#+id/Layout5"
android:layout_alignParentTop="true"
android:layout_gravity="top"
android:gravity="top"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Layout6"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="top">
<ImageView
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#color/green"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="5dp"
android:id="#+id/imageView"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_below="#+id/imageView">
<Button
android:id="#+id/btn1"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="#string/text_btn_1"
/>
<Button
android:id="#+id/btn2"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="#string/text_btn_2"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
With this layout when i am doing setContentView(R.layout.mylayout) for my activity, which has transparent theme, my layout is getting displayed in the center of the screen.
I want to change this layout positioning dynamically, so center(default) and bottom(by using following code) display is working.
LinearLayout lLayout = (LinearLayout) findViewById(R.id.Layout6);
RelativeLayout.LayoutParams relativeParas = (RelativeLayout.LayoutParams) lLayout.getLayoutParams();
relativeParas.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lLayout.setLayoutParams(relativeParas);
But somehow i am not able to figure out how to display this layout dynamically to the top of the screen.
Any help will be appreciated.
Try removing the rule that you made earlier (setting it to align bottom), and add a new rule:
//your code.
LinearLayout lLayout = (LinearLayout) findViewById(R.id.Layout6);
RelativeLayout.LayoutParams relativeParas = (RelativeLayout.LayoutParams) lLayout.getLayoutParams();
relativeParas.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lLayout.setLayoutParams(relativeParas);
//remove rule
relativeParas.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
relativeParas.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lLayout.setLayoutParams(relativeParas);
Note that removeRule() is available from API 17 onwards.
Try modifying following way:
layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Layout5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#color/yellow"
android:padding="2dp"
android:paddingLeft="5dp"
android:paddingRight="5dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#color/green"/>
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/imageView"
android:orientation="horizontal">
<Button
android:id="#+id/btn1"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="button1"
/>
<Button
android:id="#+id/btn2"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="button2"
/>
</LinearLayout>
</RelativeLayout>
class:
RelativeLayout Layout5 = (RelativeLayout)findViewById(R.id.Layout5);
Layout5.setGravity(Gravity.BOTTOM);
I found the following fix for this issue.
I added filler Liner layout in the end under Relative layout.
To display in center don't do anything.
To display in top use following code. Just move filler layout to bottom.
LinearLayout lLayout = (LinearLayout) findViewById(R.id.filler);
RelativeLayout.LayoutParams relativeParas = (RelativeLayout.LayoutParams) lLayout.getLayoutParams();
relativeParas.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lLayout.setLayoutParams(relativeParas);
To display in bottom use following code. i.e. move layout6 to bottom.
LinearLayout lLayout = (LinearLayout) findViewById(R.id.Layout6);
RelativeLayout.LayoutParams relativeParas = (RelativeLayout.LayoutParams) lLayout.getLayoutParams();
relativeParas.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lLayout.setLayoutParams(relativeParas);

Change RelativeLayout from Java in Android

I have this XML RelativeLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeBackGround"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="right"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" >
<ImageView
android:id="#+id/img1"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/sample" />
<LinearLayout
android:id="#+id/linout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/img1"
android:background="#drawable/bubble_left" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text1" />
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="text2"
android:textSize="10sp" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
What I'm trying to to do is to change the gravity of the RelativeLayout from right to left based on the row like so
wrapper = (RelativeLayout) view.findViewById(R.id.relativeBackGround);
if (even) {
wrapper.setGravity(Gravity.LEFT);//this one isn't working
//How can I change the alignment of linout to be on the left of the img1?
} else {
wrapper.setGravity(Gravity.RIGHT);
}
the setGravity isn't working, and I'm not sure how to do the alignment, can you help me with that?
You can set the layout of the LinearLayout with something similar to the following:
LinearLayout ll = (LinearLayout) view.findViewById(R.id.linout);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
ll.setLayoutParams(lp);
Then just switch the rule based on whether it's odd or even row.

Every View stick together when loop LayoutInflater

I have a layout problem. my code have a LayoutInflater set the following xml as layout, and will loop few time to show my school time table. Eventhough i have set the relativelayout's marginBottom and Top to 50dp, but why every layout still stick together?
here's the xml:
<RelativeLayout
android:id="#+id/left_part"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<TextView
android:id="#+id/table_day"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_above="#+id/table_date"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="#string/table_day"
android:textSize="#dimen/table_day_size" />
<TextView
android:id="#+id/table_date"
android:layout_width="match_parent"
android:layout_height="14dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="#string/table_date"
android:textSize="#dimen/table_date_size" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/center_part"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/left_part"
android:layout_alignTop="#+id/left_part"
android:layout_toRightOf="#+id/left_part" >
<RelativeLayout
android:id="#+id/center_part1"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<TextView
android:id="#+id/table_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/table_time"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="#dimen/table_timelocationclass_size" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/center_part2"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/center_part1" >
<TextView
android:id="#+id/table_subject"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:padding="1dp"
android:gravity="center_vertical"
android:text="#string/table_subject"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="#dimen/table_subject_size" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/center_part3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/center_part2" >
<TextView
android:id="#+id/table_lecturer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="#string/table_lecturer"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="#dimen/table_lecturer_size" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/right_part"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/center_part"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/center_part"
android:layout_toRightOf="#+id/center_part" >
<RelativeLayout
android:id="#+id/right_part1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<TextView
android:id="#+id/table_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/table_location" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/right_part2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/right_part1" >
<TextView
android:id="#+id/table_class"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/table_class" />
</RelativeLayout>
</RelativeLayout>
Here is the print screen:
here is the loop:
LinearLayout ll = (LinearLayout)findViewById(R.id.main_table);
ll.removeAllViews();
//set table layout
for(int i=0;i<tableRow.size();i++)
{
LayoutInflater inflater = getLayoutInflater();
View perClassTable = inflater.inflate(R.layout.perclass_table, null);
TextView table_day = (TextView)perClassTable.findViewById(R.id.table_day);
TextView table_date = (TextView)perClassTable.findViewById(R.id.table_date);
TextView table_time = (TextView)perClassTable.findViewById(R.id.table_time);
TextView table_location = (TextView)perClassTable.findViewById(R.id.table_location);
TextView table_class = (TextView)perClassTable.findViewById(R.id.table_class);
TextView table_subject = (TextView)perClassTable.findViewById(R.id.table_subject);
TextView table_lecturer = (TextView)perClassTable.findViewById(R.id.table_lecturer);
table_day.setText(date[i].substring(0, 3));
table_date.setText(date[1].substring(4,13));
table_time.setText(time[i]);
table_location.setText(loca[i]);
table_class.setText(clas[i]);
table_subject.setText(subj[i]);
table_lecturer.setText(lect[i]);
//testing
ll.addView(perClassTable);
}
Set some LayoutParams with some margins for your inflated view at the end of the for loop:
//...
table_subject.setText(subj[i]);
table_lecturer.setText(lect[i]);
// set some proper LayoutParams for the inflated View which is going to be added
// to the ll LinearLayout
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
// set some margins to distance the rows
lp.topMargin = 100;
lp.bottomMargin = 100;
// add the inflated view with to ll with the LayoutParams above.
ll.addView(perClassTable, lp);
}
The LayoutParams is a special class designed to be use with a ViewGroup subclass which generally holds layout attributes like width/height, margins, layout positioning rules etc.
Also, you could improve the layout file by removing all those wrappers RelativeLayouts and set the TextViews directly in the parent RelativeLayout. If the number of rows is big you may also want to have a look at the ListView widget as galex said in his answer.
A RelativeLayout evaluates it's children from top to bottom. So, if you use something like android:layout_above="#+id/table_date", it must come after table_date.
<RelativeLayout
android:id="#+id/left_part"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<TextView
android:id="#+id/table_date"
android:layout_width="match_parent"
android:layout_height="14dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="#string/table_date"
android:textSize="#dimen/table_date_size" />
<TextView
android:id="#+id/table_day"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_above="#+id/table_date"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="#string/table_day"
android:textSize="#dimen/table_day_size" />
</RelativeLayout>
Here, I have swapped the textviews.
Looks like a list to me, look into ListView.
It will even recycle views if you implement your adapter correctly!

Popup message like Dialog

I'm actually coding an app for Android and I need some help to do something.
I need to do a kind of popup message with this image: http://img716.imageshack.us/img716/9331/postitz.png. This image must have 2 TextView, one of them is a title and the other one is the message.
I have tried some options like Dialog with its own layout, own style, but the image fills all the screen instead of wrap the content of the TextViews. I have also tried to do it with a new Activity and occurs the same, the Image fills all the screen.
My actual layout is this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical"
android:background="#android:color/white">
<LinearLayout
android:id="#+id/img_postit"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/postit"
android:orientation="vertical">
<TextView
android:id="#+id/note_titulo"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="30dp"/>
<TextView
android:id="#+id/note_descr"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="30dp"/>
</LinearLayout>
</LinearLayout>
But I have tried with a lot of different combinations, RelativeLayout, FrameLayout, and I cannot find the solution to do this.
Any idea of how to resolve it?.
Thank's for all.
you said you used as a new activity. Did you use android:theme="#android:style/Theme.Dialog in your manifest file?
And be sure that the image is little bit smaller one such that it will be suitable to act as a pop up..
If you used a dialog what exactly is the problem? Didnt you get the dialog as a pop up ?
(i think the image is larger so that it might fill the entire screen)
Create your own class extending dialog.And use layout like following. I use this in one of my apps and the dialog window is wrapped around the buttons :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/ll2"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_below="#+id/ll1"
android:gravity="left"
android:orientation="horizontal"
android:paddingBottom="5dp" >
<RadioButton
android:id="#+id/start"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/stop"
android:background="#drawable/start_on"
android:button="#android:color/transparent"
android:checked="true" />
<RadioButton
android:id="#+id/stop"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="#drawable/stop_off"
android:button="#android:color/transparent" />
<RadioButton
android:id="#+id/restart"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/stop"
android:background="#drawable/restart_on"
android:button="#android:color/transparent" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/lltext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/detail_credit"
android:layout_below="#+id/ll2"
android:layout_marginBottom="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/startText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/stopText"
android:text="#string/start_server_icon"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/stopText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:text="#string/stop_server_icon"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/restartText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/stopText"
android:text="#string/restart_server_icon"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_below="#+id/lltext"
android:layout_centerHorizontal="true"
android:text="OK" />
</RelativeLayout>
final Dialog dialog_my = new Dialog(FIRST.this,
android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialog_my.setContentView(R.layout.about_us); //<PUT YOUR LAYOUT ID HERE>
TextView date = (TextView) dialog_my.findViewById(R.id.date);
TextView thought = (TextView) dialog_my.findViewById(R.id.thought);
TextView ok = (TextView) dialog_my.findViewById(R.id.ok);
TextView link = (TextView) dialog_my.findViewById(R.id.link);
TextView contact = (TextView) dialog_my.findViewById(R.id.contact);
WindowManager.LayoutParams lp = dialog_my.getWindow().getAttributes();
lp.dimAmount = 0.0f;
dialog_my.getWindow().setAttributes(lp);
dialog_my.getWindow().addFlags(
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog_my.show();

Problems positioning with layout Inflate

I have a layout A composed by a set of 2 texts and one image followed by another set of 2 texts and one image (they are separated by a line). I want to inflate this layout (lets say A) and put it inside another one (lets say B). The problem is that the images and the separator are getting in the middle of B, while I wanted them in the middle of A. My code is:
Layout A (to be inflated):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootLayout"
android:layout_width="fill_parent"
android:layout_height="55dp"
android:background="#drawable/bg_numeros"
android:orientation="vertical" >
<ImageView
android:id="#+id/separator"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/divisoria_numeros" />
<ImageView
android:id="#+id/artistsDoll"
android:layout_width="60dp"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/separator"
android:scaleType="fitCenter"
android:src="#drawable/boneco_artistas_numeros" />
<ImageView
android:id="#+id/songsDoll"
android:layout_width="60dp"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:scaleType="fitCenter"
android:src="#drawable/bonecos_numeros" />
<TextView
android:id="#+id/songsNumbers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/artistsDoll"
android:layout_toLeftOf="#+id/songsDoll"
android:layout_toRightOf="#+id/separator"
android:text="blabla"
android:textColor="#333333"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="#+id/songsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/songsNumbers"
android:layout_toLeftOf="#+id/songsDoll"
android:layout_toRightOf="#+id/separator"
android:text="SOME SONGS"
android:textColor="#999999"
android:textSize="11dp" />
<TextView
android:id="#+id/artistsNumbers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/artistsDoll"
android:layout_toLeftOf="#+id/artistsDoll"
android:text="blabla"
android:textColor="#333333"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="#+id/artistsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/artistsNumbers"
android:layout_toLeftOf="#+id/artistsDoll"
android:text="SOME ARTISTS"
android:textColor="#999999"
android:textSize="11dp" />
</RelativeLayout>
I am inserting the inflated layout like this:
RelativeLayout A = (RelativeLayout) Patterns.mainContext
.getLayoutInflater()
.inflate(R.layout.A, null);
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
rlp.addRule(RelativeLayout.BELOW, someTopLayout.getId());
B.addView(A, rlp);
Note that although the attributes android:layout_height="fill_parent" and android:layout_centerHorizontal="true" are set for the images, I expected them to centered in A, not B.
Any help??
The solution found here: How to use layoutinflator to add views at runtime?
Solved my problem.
RelativeLayout A = (RelativeLayout) Patterns.mainContext
.getLayoutInflater()
.inflate(R.layout.A, parentLayout, false);

Categories

Resources