Solved

RelativeLayout Android question

Posted on 2011-09-10
6
430 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
android app layout 7 101
Galaxy Note 4 System Update FAIL 13 106
Auto-rotate google map 1 86
Need to track Android phone using GPS when there is no Internet on the phone. 4 45
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ā€¦
This is an explanation of a simple data model to help parse a JSON feed
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.

776 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