dpi与dp的关系,缩放与DPI的图像,而不是DP之间的区别

I have all of the dpi drawable directories (are xxhdpi and xxxhdpi even necessary?) consisting of nine-patch bitmaps, the drawable resource file in the drawable directory that retrieves all of the scaled bitmaps, and I set the backgrounds of the Buttons with the drawable resource file... Now, my problem is that I also created "scaled" layout directories in terms of size (small, normal, and etc.), in which I tried to manually change the dp of the buttons as follows:

Here's my xhdpi bitmap:

1w5a6.png

... But it appears like this on the Nexus 7 virtual emulator (7.0", 1200X1920: xhdpi) in the layout-large directory:

r4dJh.png

... And when I manually change the dp size to 200 of one of the buttons:

5ht9R.png

^^^ How do my directories look by the way? ... And why does the button appear like that? ^^^

All of that said, I just don't understand why we need density-based drawable directories (mdpi, hdpi, xhdpi, and etc.) as well as layout resource directories, when we could just simply modify the dp of images in each unique layout regarding the screen's size (small, normal, and etc.).

解决方案

@dpark14 I basically already answered the question you asked in a your post from yesterday here: Is modifying the dp size as opposed to pixels recommended for various screen sizes?

Perhaps you should have edited your last question to include the code and images above so it could be consolidated.

As I said in my answer (and one of the other comments said):

It is entirely up to you if you want to change the layout width and height (in dp) of an imageButton. There is certainly nothing wrong with setting width and height of an imageButton or any UI element for that matter, in each unique layout resource file for various screens. Did you have specific code you wanted to get feedback about?

Now that you have included some images I can see some of what you have.

You should really take a look at this:

Android Studio drawable folders

And it would benefit you to read through the Android documentation again:

http://developer.android.com/guide/practices/screens_support.html

To summarize a few general ideas:

You don't need a default drawable folder, but you should have the following:

drawable-mdpi (medium) ~160dpi

drawable-hdpi (high) ~240dpi

drawable-xhdpi (extra-high) ~320dpi

drawable-xxhdpi (extra-extra-high) ~480dpi

drawable-xxxhdpi (extra-extra-extra-high) ~640dpi

As the Android documentation says in the link above:

Your application achieves "density independence" when it preserves the physical size (from the user's point of view) of user interface elements when displayed on screens with different densities.

mMSGH.png

Instead of:

Kcqt1.png

If, for some reason (as it looks like you're having issues with) you've achieved density independence, but your image doesn't fit well, that's when you can start to step in with changes to w/h and res/layout

Also from my previous answer:

As you alluded to: you could create different res/dimens directories for various devices based on "minimums" e.g. w800dp/dimens.xml and then create elements in that specific dimens.xml e.g. values-w411/dimens.xml for width and height that correspond with your images that aren't fitting well when you test your app.

As a first step, perhaps you should try it out. Yes, this takes time, but try a stand-alone test separate from your app first. Just add one image (perhaps the one you are having issues with). See what happens when you load it into different Nexus devices in the emulator. Does the image achieve "density independence" i.e. preserves the physical size across devices? If it does, and there's an issue with its w/h in relation to the confines of a specific device, as I said in my previous answer and now here, create a dimens directory (within a values-... directory) specifically for the problem device and change the layout_width/layout_height for that specific image or view.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值