How to deal with multiple screens + dynamic controls in Android?

I am learning how to program on an Android phone. However, I'm not sure how to get the application to work with different screen sizes and resolutions.

I read the tutorial on android site and still don't know how to do it.

At first I know that there are different files, so you can make a layout for each of the sizes, but my problem is that most of the screen needs to be dynamically created, so there wouldn’t be much to insert these files.

So I'm not sure how to resize dynamic elements based on Android screen size.

I also read that it is bad practice to create controls in everything except the xml file, since it separates presentation logic and programming logic. However, they never talk about whether you need to dynamically control these controls, what you should do.

So, is there another way to do this, which is considered good practice?

Edit

I get this error when I try to start a switch application.

[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: Error type 2
[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: Error: Unable to connect to activity manager; is the system running?
[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: usage: am [start|broadcast|instrument|profile]
[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: am start [-D] INTENT
[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: am broadcast INTENT
[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: am instrument [-r] [-e <ARG_NAME> <ARG_VALUE>] [-p <PROF_FILE>]
[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: [-w] <COMPONENT>
[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: am profile <PROCESS> [start <PROF_FILE>|stop]
[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: INTENT is described with:
[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: [-c <CATEGORY> [-c <CATEGORY>] ...]
[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: [-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[2010-04-27 12:06:41 - ViewSwitcherTest] ActivityManager: [-n <COMPONENT>] [-f <FLAGS>] [<URI>]

: , 3 , (, , , ). , 0.75px, 1.0px 1.5px. Android . , .

, , ?

, "" . . "". , . , . . "Scrn" 4 . ( , , ). "Enter" . Eclipse.

, , ? ?

(.. )?

, ? , -, :

checkbox label label

10 000 , , -, ( ).

+3
3

: , , (, , , ). , 0.75px, 1.0px 1.5px. Android . . , , "" . , . "". , , . , , . . "Scrn" 4 . ( , , ). "Enter" . Eclipse. : http://android.pithax.net/ViewSwitcherTest.zip

0

, . 3 , , . , xml - , . . , , :

(, , " " , DisplayMetrics:

public class YourActivity extends Activity {

private DisplayMetrics metrics = new DisplayMetrics();
private float density;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    density = metrics.density;  
    ....

}

0,75, 1,0 1,5. , , . "" . , .

0

, , ?

-, "". , .

, , ? ?

"" . view1.setHeight((int) ( 350 *)); , 350px, 350sp. , sp, dip px. . ( ), , , , . Android , (), , , , . , . , , .

will scaled pixels work with changing from portrait to landscape( ie will it fill up the new found space)?

, . , , , .

, ? , -, :

10 000 , -, ( ).

, . . , . , .

, xml. ( ). , , , , , , . , , . , Android .

: "./adb logcat"? , Android API 4, , ( drawable-ldpi hdpi "drawable" ), . . Android-. , , (net.pithax.viewswitchertest). zip , zip.

0

Source: https://habr.com/ru/post/1742526/


All Articles