Solved

RelativeLayout Android question

Posted on 2011-09-10
6
421 Views
Last Modified: 2012-05-12
How do I convert following XML to use in Java code?

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="195dp"
  android:layout_height="29dp"
>

Thanks,
Ashok
0
Comment
Question by:Ashok
  • 3
  • 3
6 Comments
 
LVL 24

Accepted Solution

by:
alexey_gusev earned 500 total points
ID: 36521637
you can get RelativeLayout itself like this:


RelativeLayout rlt = (RelativeLayout)findViewById(R.id.yourid); // give it id in xml file

Open in new window


then you can set various parameters on it.

Alternatively, you can use LayoutParams from view (http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html) and then change appropriate settings.
0
 
LVL 13

Author Comment

by:Ashok
ID: 36522145
In my Android Project, I do not have layout folder.
I do not want to use layout xml (in layout foleder).

I am already creating all layout (LinearLayout, RelativeLayout, TextView, ImageView, EditText, LayoutParams) in code.
In my previous Android Project, I used above xml as I specified.

What I want to find out is "How to code above same xml code in Java Source code".

The only difficulty is to conver these 2 lines
  android:layout_width="195dp"
  android:layout_height="29dp"

Thanks,
Ashok
0
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 36522210
call getLayoutParams() and then use it's height and width members to set what you want and finally set it all back
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Author Comment

by:Ashok
ID: 36522456
Is that without having XML file in layout folder?

Ashok
0
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 36522499
if you looked at the link, it is for View documentation. RelativeLayout inherits from it indirecly, hence regardless of how you created your instance (by inflating or however you did it), you can all its methods.

so it'll be something like

RelativeLayout.LayoutParams lp = relativeLayoutAshok.getLayoutParams();

Open in new window

0
 
LVL 13

Author Closing Comment

by:Ashok
ID: 36546801
Not complete solution I was looking for.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Android SDK is used for creating an android software application. It includes document and tools which are necessary to develop applications with java. In fact Android SDK is harder than other software infrastructure, because there is a virtual devi…
A short article about a problem I had getting the GPS LocationListener working.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now