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
Solved

RelativeLayout Android question

Posted on 2011-09-10
6
440 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Got a software and it removed my google search 6 147
MITM attack on Android phones 8 121
Syncing android phone with pop three account 3 38
Place to store Android app 19 84
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
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…

839 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