I would like to know whether there is such possibility to customize the screen size on Android devices? Something like using half part of the screen and the other half is blank.
For this kind of problems, you can work with percentage. There are 2 common ways:
in java:
You can get the display height from your used lcd-panel and then multiply with your number of percents. In this way, you have to format the button in your activity.
in layout xml:
You should design your layout within the xml-files and not in java code (my oppinion). Use layout-weight like following post: set position size of ui element as percentage of screen size
Related
Hi I am developing an app for large screens (24 inch - 30 inch) and I need a way to make it easier for wheelchair users to use the app. The first idea I have is resize all activities to a percent (50%) and put layout to bottom left or right. But I dont know how it can be done and need help or a different solution for the problem.
What i want is with a button click resize activity layout to example below. orange color represents activity and black orange image is when activity size reduced to size.
You can set other xml which have difference size which make you can design your UI depend what type device user used. There four type size = small, normal, large, and extra large (CMIIW). You can use this for reference
Adapt layout to all screen resolution - Android
https://youtu.be/th9YQ8nmhNg
I am attempting to make an 8x8 matrix of coloured squares on a black background in a layout that is limited to portrait only. I need the squares to all be equal in size, and the overall matrix to be 60% of the screen's width and of equal height. I also need to control the colour of each square dynamically as a result of my code, call it a pattern setting code if you will. Here is an example of what I need the final product to look like:
Screen example
I have been researching different ways of doing this and was hoping for some advice on the best approach. Here are some ideas I had:
1) Use GridLayout (not GridView) and set the background of each cell to the required colour. This shouldn't be difficult to control with java, but how do I enforce the correct dimensions? Would I need to fill each grid cell with something of a certain size, or can I use layout_weight attributes to control the dimensions?
2) Use a combination of RelativeLayout and LinearLayout with ImageView and display locally saved images of coloured squares. Can I use layout_weight to control the size of these images, and if these images were too small would they be stretched to fill their required dimensions? (I'm thinking of larger tablet screens.)
What I really need from someone is some sample code to implement a very simple version of what I need (for example one square in the centre of the screen that I can colour-control dynamically). Obviously I can then expand it to my specific requirements. If more details or code are required I will happily post them.
Perhaps you could just create a custom View object, and render the appropriate bitmap in the onDraw method? Seems like overkill to use layout objects, unless you're planning to do more than just render squares of colour?
Edit: Alternatively, I once used the info in the following posting to programmatically build a layout grid. It's not exactly what you need (it generates as many horizontal 'cells' as are necessary), but should make for insightful reading on manipulating layout dimensions:
Line-breaking widget layout for Android
I want to create my button height using drawable xml file and it should also resize dynamically with my layout, so that it can support any Android device.
Currently I am using RelativeLayout with match_parent height. I want to put a set of 3X4 buttons in this layout and should automatically resize with the device height.
I am not able to resize it properly when I use dp values. If I resize the button for large res device, it is not working fine for 240X320 res device.
Yes, you should be able to do what you want with the Android layout classes. You aren't completely clear, but it sounds like GridLayout is what you want.
The default Android UI element should deal well with being sized dynamically; if you have a custom drawable asset, you'll want to make an appropriate 9-patch image at each of the common display densities (so that it not only resizes correctly, but looks good on a range of devices).
I have recently been thinking about this very topic, and I think I can help you. If I understand you correctly, you would like to have your application dynamically resize your buttons depending on the screen size. In order to do that you can use binding and a converter. If you bind your button's height (and width if you prefer) to the page's height (and width) you can use a converter to convert the value to a percentage of the screen size. If you like, I can provide you with some sample code.
You can get the size of the display Display display = getWindowManager().getDefaultDisplay(); and set the sizes dinamically.
Or, you can make various sizes of your images.
I am trying to create a calculator app and I've been having problems with the xml layout.
Due to the amount of button even though I use dp's to determine the size of each button from screen to screen the result varies...
Am i supposed to create the layout in java so I can get the screen dimensions?? if so can I have an example?
You can design the layout file and then make a few versions of it with different sized buttons. put them in res/layout-small/, res/layout-large/, and res/layout-normal/. The system will pull the proper xml file according to what size display the device has.
Another option is to try to design the layout with specifying a size in dp, instead use android:layout_weight and android:weightSum to achieve the proportions you are wanting. Then it should scale itself based on the device without needing any different xml files.
I am developing an application for whole android devices. But resolation of screens are different and that is the biggest problem how it looks. So, I want to make resizing controls and also I used absolutelayout but It is still same.. I give value to controls as dp ..
How can I solve this problem ?
You don't resize the screen of an android device - you make your app instead work with the various screen sizes.
The relevant docs are here.
You cannot hardcode the dimensions of your layout and expect it to work on every screen size. And there is no method which automatically does it unless you write it.
You might want to change your approach, use Relative Layout or Linear Layout instead and use values like fill_parent and wrap_content while designing your layout.
Another approach Android developers follow is use different resource files for different screen sizes and Android loads them automatically at runtime.
Refer to this for more info on how to work with different screen sizes effectively.