created dynamic using xml file

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

created dynamic using xml file

Postby rmeph » Thu Jan 31, 2008 1:06 pm

using xml file i draw one round rect
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.     android:orientation="vertical"
  6.  
  7.     android:layout_width="fill_parent"
  8.  
  9.     android:layout_height="fill_parent"
  10.  
  11.    >
  12.  
  13.  
  14.  
  15. <ImageView id="@+id/img1"
  16.  
  17.      android:layout_width="304px"
  18.  
  19.      android:layout_height="84px"
  20.  
  21.      android:layout_marginTop="9px"
  22.  
  23.      android:layout_marginLeft="9px"
  24.  
  25.     android:src="@drawable/shape_2"
  26.  
  27.     />
  28.  
  29. </RelativeLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


but in static width and height......i want created dynamic.... according to emulator screen width and height is it possible using xml... :roll:
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Top

Postby rmeph » Fri Feb 01, 2008 7:02 am

if anyone know then plz tel me.......... :roll:
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby plusminus » Fri Feb 01, 2008 11:40 am

Hello rmeph,

sorry for the late answer.

Dynamically (on RunTime) probably not, because Resources-Files get compiled into your application and on compile-time the screen-resolutions of the device your application will run on is unknown.
You work XML-Layouts, because you want to be resolution-independent :!:

(Working with FILL_PARENT and WRAP_CONTENT is probably not what you are looking for)

To make it easier to change you could define Dimension-Resources:
Source file format: XML file requiring a <?xml version="1.0" encoding="utf-8"?> declaration, and a root <resources> element containing one or more <dimen> tags.

Implementation like this:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3.     <dimen name="one_pixel">1px</dimen>
  4.     <dimen name="double_density">2dp</dimen>
  5.     <dimen name="sixteen_sp">16sp</dimen>
  6. </resources>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Hope I could help you. :)

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 rmeph » Fri Feb 01, 2008 1:21 pm

Thanks for reply..... :)
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby rmeph » Fri Feb 01, 2008 5:48 pm

some problems here in xml...i used 1 imageview in xml

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <ImageView id="@+id/img1"
  2.  
  3.      android:layout_width="fill_parent"
  4.  
  5.      android:layout_height="fill_parent"
  6.  
  7.      android:layout_marginTop="10px"
  8.  
  9.      android:layout_marginLeft="10px"
  10.  
  11.     android:src="@drawable/shape_2"
  12.  
  13.     />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


i want get height and width it in onCreate(...)

i used in
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. onCreate(..)
  2.  
  3. {
  4.  
  5. ImageView im=(ImageView)findViewByID(R.id.img1);
  6.  
  7. Log.i("Canvas","im.getHeight()"+im.getHeight());
  8.  
  9. Log.i("Canvas","im.getwidth()"+im.getWidth());
  10.  
  11.  
  12.  
  13.  
  14.  
  15. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
but both is zero..how to get it??
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby plusminus » Sat Feb 02, 2008 12:42 am

Hello rmeph,

the wrong values could be related to the fact the within onCreate the Views and Layout are "not yet fully done".
Do you receive the correct values when the Activity is fully loaded :?: (like in an Button-Onclick-Listener, what works with me)

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 11 guests