?
Solved

RelativeLayout Android question

Posted on 2011-09-10
6
Medium Priority
?
456 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 24

Accepted Solution

by:
alexey_gusev earned 1000 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
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
These days software publishers make it possible to move all the possible applications on smartphones, tablets, smartwatches, and more. Although behind every logic and decision is a gross doubt: how do they make it possible? In this blog post, we sha…
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…
Suggested Courses

771 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