Mikkel Fausing
- Forum posts: 1
Sep 17, 2012, 1:57:49 PM via Website
Sep 17, 2012 1:57:49 PM via Website
Hi, new to the forum and Android development, though not to programming in general.
I'm having a hard time getting my head around Android Layouts - at least finding a way to deal with the multitudes of resolutions and screen sizes out there, preferably using one layout that scales relatively well.
Setting aside that nested weights are frowned upon, at least in apps that require fast updates, I made a layout that has some nested LinearLayout (see code), and it works as intended, whether I watch it on a small screen or a tablet - so far so good, right? However, the moment I change the background property of a LinearLayout to use a drawable resource instead of a solid color, it messes the whole thing up - why is this, and more importantly, is there something I can do to alleviate it?
I'm of course also interested in alternative ways to do the whole thing, since the nested LinearLayouts are quite horrible to me.
XML that works well enough until I change the background of a LinearLayout:
I'm having a hard time getting my head around Android Layouts - at least finding a way to deal with the multitudes of resolutions and screen sizes out there, preferably using one layout that scales relatively well.
Setting aside that nested weights are frowned upon, at least in apps that require fast updates, I made a layout that has some nested LinearLayout (see code), and it works as intended, whether I watch it on a small screen or a tablet - so far so good, right? However, the moment I change the background property of a LinearLayout to use a drawable resource instead of a solid color, it messes the whole thing up - why is this, and more importantly, is there something I can do to alleviate it?
I'm of course also interested in alternative ways to do the whole thing, since the nested LinearLayouts are quite horrible to me.
XML that works well enough until I change the background of a LinearLayout:
1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical"
6 android:weightSum="1" >
7
8 <LinearLayout
9 android:layout_width="match_parent"
10 android:layout_height="wrap_content"
11 android:layout_weight=".25"
12 android:weightSum=".25"
13 android:baselineAligned="false" >
14
15 <LinearLayout
16 android:layout_width="wrap_content"
17 android:layout_height="match_parent"
18 android:layout_weight=".0625"
19 android:background="@color/white" >
20 </LinearLayout>
21
22
23 <LinearLayout
24 android:layout_width="wrap_content"
25 android:layout_height="match_parent"
26 android:layout_weight=".125" >
27
28 </LinearLayout>
29
30 <LinearLayout
31 android:layout_width="wrap_content"
32 android:layout_height="match_parent"
33 android:layout_weight=".0625"
34 android:background="@color/red" >
35
36 </LinearLayout>
37
38 </LinearLayout>
39
40 <LinearLayout
41 android:layout_width="match_parent"
42 android:layout_height="wrap_content"
43 android:layout_weight=".5"
44 android:weightSum=".5"
45 android:baselineAligned="false" >
46
47 <LinearLayout
48 android:layout_width="wrap_content"
49 android:layout_height="match_parent"
50 android:layout_weight=".125" >
51 </LinearLayout>
52
53
54 <LinearLayout
55 android:layout_width="wrap_content"
56 android:layout_height="match_parent"
57 android:layout_weight=".25" >
58
59 </LinearLayout>
60
61 <LinearLayout
62 android:layout_width="wrap_content"
63 android:layout_height="match_parent"
64 android:layout_weight=".125" >
65
66 </LinearLayout>
67
68 </LinearLayout>
69
70 <LinearLayout
71 android:layout_width="match_parent"
72 android:layout_height="wrap_content"
73 android:layout_weight=".25"
74 android:weightSum=".25"
75 android:baselineAligned="false" >
76
77 <LinearLayout
78 android:layout_width="wrap_content"
79 android:layout_height="match_parent"
80 android:layout_weight=".0625"
81 android:background="@color/cyan" >
82 </LinearLayout>
83
84
85 <LinearLayout
86 android:layout_width="wrap_content"
87 android:layout_height="match_parent"
88 android:layout_weight=".125" >
89
90 </LinearLayout>
91
92 <LinearLayout
93 android:layout_width="wrap_content"
94 android:layout_height="match_parent"
95 android:layout_weight=".0625"
96 android:background="@color/yellow" >
97
98 </LinearLayout>
99
100 </LinearLayout>
101
102</LinearLayout>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical"
6 android:weightSum="1" >
7
8 <LinearLayout
9 android:layout_width="match_parent"
10 android:layout_height="wrap_content"
11 android:layout_weight=".25"
12 android:weightSum=".25"
13 android:baselineAligned="false" >
14
15 <LinearLayout
16 android:layout_width="wrap_content"
17 android:layout_height="match_parent"
18 android:layout_weight=".0625"
19 android:background="@color/white" >
20 </LinearLayout>
21
22
23 <LinearLayout
24 android:layout_width="wrap_content"
25 android:layout_height="match_parent"
26 android:layout_weight=".125" >
27
28 </LinearLayout>
29
30 <LinearLayout
31 android:layout_width="wrap_content"
32 android:layout_height="match_parent"
33 android:layout_weight=".0625"
34 android:background="@color/red" >
35
36 </LinearLayout>
37
38 </LinearLayout>
39
40 <LinearLayout
41 android:layout_width="match_parent"
42 android:layout_height="wrap_content"
43 android:layout_weight=".5"
44 android:weightSum=".5"
45 android:baselineAligned="false" >
46
47 <LinearLayout
48 android:layout_width="wrap_content"
49 android:layout_height="match_parent"
50 android:layout_weight=".125" >
51 </LinearLayout>
52
53
54 <LinearLayout
55 android:layout_width="wrap_content"
56 android:layout_height="match_parent"
57 android:layout_weight=".25" >
58
59 </LinearLayout>
60
61 <LinearLayout
62 android:layout_width="wrap_content"
63 android:layout_height="match_parent"
64 android:layout_weight=".125" >
65
66 </LinearLayout>
67
68 </LinearLayout>
69
70 <LinearLayout
71 android:layout_width="match_parent"
72 android:layout_height="wrap_content"
73 android:layout_weight=".25"
74 android:weightSum=".25"
75 android:baselineAligned="false" >
76
77 <LinearLayout
78 android:layout_width="wrap_content"
79 android:layout_height="match_parent"
80 android:layout_weight=".0625"
81 android:background="@color/cyan" >
82 </LinearLayout>
83
84
85 <LinearLayout
86 android:layout_width="wrap_content"
87 android:layout_height="match_parent"
88 android:layout_weight=".125" >
89
90 </LinearLayout>
91
92 <LinearLayout
93 android:layout_width="wrap_content"
94 android:layout_height="match_parent"
95 android:layout_weight=".0625"
96 android:background="@color/yellow" >
97
98 </LinearLayout>
99
100 </LinearLayout>
101
102</LinearLayout>
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.