Apply xml attribute to view in java code

Put your problem here if it does not fit any of the other categories.

Apply xml attribute to view in java code

Postby agent00 » Fri Jan 18, 2008 5:17 pm

Hi everybody,

I'm looking for a way to apply some attributes in my views but without using xml file.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <LinearLayout
  2.   id="@+id/widget25"
  3.   android:layout_width="fill_parent"
  4.   android:layout_height="wrap_content"
  5.   xmlns:android="http://schemas.android.com/apk/res/android"
  6.   >
  7.  
  8. <AnalogClock
  9.   id="@+id/widget28"
  10.   android:layout_width="50px"
  11.   android:layout_height="50px"
  12.   android:layout_gravity="center_vertical"
  13.   />
  14.  
  15. <TimePicker
  16.   id="@+id/widget29"
  17.   android:layout_width="wrap_content"
  18.   android:layout_height="wrap_content"
  19.   android:layout_gravity="center_vertical"
  20.   />
  21.  
  22. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4

Here is the XML code of what i'm trying to do in java. Mainly the android:layout_gravity="center_vertical" of the time picker and the android:layout_width="fill_parent" of the linear layout.

Anyone can help me ?

Thanks

Regards, Agent00
agent00
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Jan 18, 2008 4:23 pm

Top

Postby plusminus » Fri Jan 18, 2008 6:46 pm

Hello agent00,

this should help you further:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         LinearLayout linLay = (LinearLayout)findViewById(R.id.theLinearlayout);
  2.         linLay.setGravity(Gravity.CENTER_VERTICAL);
  3.         linLay.setLayoutParams(new LinearLayout.LayoutParams(
  4.                         LayoutParams.FILL_PARENT, // Width
  5.                         LayoutParams.FILL_PARENT) // Height
  6.                 );
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

(code is untested!)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby agent00 » Mon Jan 21, 2008 11:23 am

Thanks plusminus but I have a probem. The text isn't fully displayed.
Image

PS. How can I resize an ImageView. I found the way to get width and height but not how to set it !

Thanks,

Regards.
agent00
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Jan 18, 2008 4:23 pm

Postby plusminus » Mon Jan 21, 2008 5:33 pm

Hello Agent00,

please post the relevant code :) .

Do you really have to set the size of the ImageView explicitly :?: I don't know your program but the Layouts should manage resizing and stuff, perhaps it's better to add a attribute for automatic-resizing.
:idea: Width and Height of a View are defined using the LayoutParams as done above.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 14 guests