How to set width and height of a View in DP through code not in XML ?

by Mansoor » Thu, 27 Jan 2011 13:47:47 GMT

Sponsored Links
 hi ,
i am creating a Image view  through code dynamically based on certain
condition as below:

ImageView t = new ImageView(mContext);
t.setLayoutParams(new LinearLayout.LayoutParams(390,
the width and height is in PX i.e 390 PX and 300 PX

but i want to know how to set width and height in dp instead of px
programmatically . In xml we can do but i have no idea how to do it in
please help me .

Mansoor V.M


Other Threads

1. palringo messanger .. bbm killer hehehe

hallo pengguna android .. pada pake palringo dunk .. ntar isa create room
android (uda ada sih .. tp kebanyakan orang ga jelas), dan isa bikin room2
isa kirim2 gambar lgsg, voice jg isa, bisa masukin messanger2 lainnya
seperti ym, msn, gtalk, fb dll .... seru nih

beta terakir versi 0.006 uda lmyn ... saya sudah pake sejak beta 0.04 sih

bikin iri pengguna bbm dan bb nih hehehehe, soalnya isa ketambahan send
voice dan yg pasti multiplatform, jadi user nya macem2, dari ipong,
simbiyan, winmo, japa, andorid ... bb pun jg bisa, tp kebanyakan ga mau pake
kalo pengguna bb .. kan ga exclusive gitu lo hehehehe

kalo dl jgn yg di market android .. kuno dl disini lgsg :

"Indonesian Android Community [id-android]" 

2. AppFriend for Facebook/Twitter (Social discovery of apps)

I've been looking into social discovery of Android applications and have
found the space saturated with a lot of players. Most of these seemed to
focus on aggregated data (AppAware, AppBrain). What I wasn't able to find
was a simple way to just share apps that you like with your friends. So I
came up with an Android application 'AppFriend for Facebook' as an
experiment to see if people in a friend-to-friend network would be
interested in sharing application info.

The usage is growing each day, so I feel comfortable in approaching the dev
community and asking you guys to check it out as a way to promote your apps
to users and to get the word out about your application(s).

It's a really simple Android application that allows users to look at their
installed apps on their device and comment on them. The comment and catalog
info is then placed on their facebook wall and can be further shared among

You can find it by searching for appfriend on Android Market or for QR codes
go to: (Facebook version) (Twitter Version) - You can choose
option {Likes, Is using, #PaidAppPledge}

On Alternative Market:

For a list of currently shared apps

Have fun,

Shane Isbell (Founder of ZappMarket)


3. Launching an "About" screen from Preferences

4. How can my app let people pick a picture that I use as background in my app?

5. read default browser cookies for webview

6. Multiple Back Button clicks needed to exit application

7. Oot : (closed) deal transaksi