I restart to develop an app which I stop to work on it years ago.
I would to move from Eclipse to Android Studio, but before I tried to check if it works with the Nexus5 I actually have. The app was tested on Nexus S.
After compiling and starting I get a lot of NullPointerException and I saw that depends on different findViewById not resolved.
I was using only the res/layout folder.
I tryed to copy that folder to a new folder named res/layout-large and all works fine.
My questions are:
Is there no way to use only res/layout ?
I have to rename it to res/layout-normal because res/layout isn't anymore the default layout folder, or not?
Do I need to introduce also the other folders (res/layout-normal and so on) ?
Thanks
Luca
-large -xlarge and so on have been deprecated for quite some time.
The documentation is not always up to date but it is recommended to use -sw<N>dp instead, for example layout-sw600dp
You don't have to use anything else than the base selector (layout, values, drawable, etc) for any kind of resource, so your problem seems to be in how you declare and use these resources.
Related
before when I was creating a new project I was found this folders drawable-hdpi,drawable-mdpi, drawable-xhdpi, and drawable-xxhdpi. but now they are all gone!
is there any explanation of what happens?
and where we should put our images?
This is perhaps because they will add an Gradle plugin that converts SVGs to PNGs during build (as mentioned in this IO talk). The idea is that you will only need to have a single SVG instead of multiple PNGs for various densities (an thus, only one drawable folder). You can still create the folders and use PNGs.
The Gradle plugins for SVG conversion by Google has not been released yet, but you can use Victor or a similar plugin if you already want to use SVGs for your drawables.
You should read Android Blog
you can just create drawable-xhdpi.
I just give answer here
read and if any problem ask.
I wasn't aware that Android Studio ever provided these dpi dependent drawable folders for the built-in default project scaffolding, and indeed, why should they?
Are they supposed to guess that you're going to support each and every one of these resolutions? Perhaps all your graphics will be vector graphics? Perhaps you only target low or high resolutions?
Also, the DPI modifier is only 1 of the possible modifiers you can attach to a resource folder. You can also add locale, screen width / height, mobile country code and many more. Should Android Studio create a folder with each of these options, along with every possible variation? You'd end up with thousands of folders which you'd likely never use.
In addition, creating a folder with no assets inside it is a big problem when you start synchronising your code using Github or something similar, and creating every possible folder with default assets inside seems like a huge waste.
I think the best approach here is to create any resource folder you need when you need it. Google leaves this decision to you.
Also, important: There is no XDPI or XXDPI folder - it's XHDPI, and XXHDPI
Check in your project section, Not in android section, If they gone just simply create them
In android project there are multiple folders, I know you can simply override these with one 'Drawable' folder.
My question is: When people download my app, will it take up more room if I have manually catered to all the different Drawable folders instead of just overriding them with one?
yea, but your app will be slightly slower, cause android has to re-size the images (whereas if you have different folders it uses the respective images)
Yes, different Drawable is for different dpi based device screen and its part of APK.
When you download APK then even drawable is also part of it and it gets stored on device and it does take space.
Different Drawable folders in android directory is for supporting different screen sizes. for better UI experience you should put drawables in appropriate folders.I think you should have look into it before proceeding further Know android project directories
So I am not such a newbie in Programming, Java or Android developing, but I got a strange issue: I have made an application, quite advanced, and have it on market.
For now I have over 1000 installs and I have around 4 or 5 crash reports for a ResourceNotFoundException. The strangest thing is that the line it crashes on is on
setContentView(R.layout.some_custom_layout)
In code I am always referring to resourced by
someTxtView.setText(R.string.some_string)
So I am wondering if I used
mContext.getResources().getDrawable(mContext.getResources().getIdentifier("some_string", "string", "my.example.package"));
would the crash go away?
I was facing the same issue and I fixed it by creating Layout Folder called "layout-small".
Based on resolutions I have created only 2 folders "layout-large" and "layout-medium". But few phones are having lower resolution it doesn't find proper resources as per the resolution. Android OS renders xml resources as per resolution. It goes and find the resources in required folders.
95+ % Android phones having resolution which matches "layout-normal" folder. But still there are Phones having lower resolution. Hence this issue occurred.
For more Details : http://developer.android.com/guide/practices/screens_support.html
Hope this helps your problem.
If you are calling setContentView(R.layout.some_custom_layout) from the Activity's onCreate method, you should be good as long as your app compiles (and I assume it does).
AFAIK accessing your string resources via:
someTxtView.setText(R.string.some_string)
is not the way to go. You should be doing this:
getContext().getResources().getString(R.string.some_string)
Except
setContentView(R.layout.some_custom_layout);
try using
setContentView(yourpackagename.R.layout.some_custom_layout);
that helped me a lot of times.
I have one suggestion. Do you use in your layouts android secific resources, such as drawables or something, for example
android:backgroud="#android:drawable/some_android_drawable"
Maybe some vendors don't provide some resources with their firmware, so your app crashs.
for example this issue
someTxtView.setText(R.string.some_string)
There you set integer value to text. Its not correctly becouse it search a resousre on this value. You must write
someTextView.setText(getResources().getText(R.string.blabla));
I have an app on the iPhone and need to port it to android. For this I would like to group screen related files like classes and xml per screen in one "screen group" per screen somehow, ideally also strings and other value files
if I use folders I can only group res files separately and src files separately.
what would be the best way?
Thanks very much!
EDIT:
If that should not be possible, how to best then solve this issue? Do you create a subfolder in the src and another in the res for each screen?
The way you group files for the iphone is not possible for an android project. Android has pre determined folders which hold specific files, if you break this structure, your building process will fail. Its not ideal but that just how it it.
When it comes to source java files, they follow the concept of packages which are basically folders. The 'src' folder is the part where you can create sub folders as you desire. If you are adamant about keeping the files related to a screen in one place, you should create the layouts with java code and not use layout xml files.
But using xml layout files make development much easier and faster. Consider that as the presentation and java files as the logic+data. So group java files as you want and leave xml files in the layout folder with easy to identify names.
android uses certain directory layout for project structures (i.e. convention over configuration). Basically you will want to put your XML layout files in res/layout directory. Please read http://developer.android.com/guide/developing/projects/index.html#ApplicationProjects for further information.
Unfortunately, there's no easy way to do this in Eclipse. You can't create custom directories in your Android app's /res directory, you can only use permitted dir-names. E.g. you can't have a /res/layout-myscreen1 and /res/layout-myscreen2. You also must put your resources in /res, and your code files in packages, so they're at separate places in your project.
You can use Working Sets to group related files together however, but they're quite painful to use IMHO. Check the eclipse docs and tutorials out on them.
I'm developing an android app, I'm testing with samsung galaxy tab, for any reason my xxx_layout.xml is not working, it remains in its first version, if I modify it none of this changes are viewed, I make all the process to generate an signed apk, clear any data in the tablet before install but this problem still appearing.
Please any sugestion or solution is welcome, thanks
Greetings
Do you have another definition that is ovrriding this one?
Files in res/layout/ are "defaults" or fallback versions that are used when no better one is found. Now on a tablet,with a hdpi or xlarge screen, layouts in res/layout-hdpi or res/layout-xlarge are taken before the ones in res/layout.
can you make sure that this layout file is actually used.
also check if you have any errors in the layout file.