Solved

RelativeLayout Android question

Posted on 2011-09-10
6
410 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
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.
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.

757 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

20 Experts available now in Live!

Get 1:1 Help Now