Toon posts:

Android xml layout is resolutie afhankelijk

Pagina: 1
Acties:

Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Edit: ik heb het opgelost, het was heel simpel: in de bovenste LinearLayout de gravity en gravity_layout beide van "center_vertical" in "top" veranderen.
code:
1
2
              android:gravity="top"
              android:layout_gravity="top"


Ik onderhoudt voor eigen gebruik een fork van de messaging app Signal. Voornaamste verschil met de officiele versie is dat ik encrypted backup en restore, die ooit in oude versies zaken, terug ingebouwd heb (met enkele kleine verbeteringen). Dit zorgt er voor dat je je complete installatie kunt overzetten naar een nieuw toestel, ook als egeen root hebt en dus geen tools als Titanium Backup kunt draaien.

Dat werkt allemaal, maar nu in Signal 4.0 de layout van het backup/restore scherm aangepast en ik krijg de layout niet goed in mijn aangepaste versie (de functionaliteit werkt wel). Alle aanpassingen in de source die ik gemaakt heb staan op https://mega.nz/#!5cBm1Ag...rLFD-5OCd-yEhDSKypx1BYyY0.

Het draait om import_export_fragment.xml: als ik gewoon de extra velden voor encrypted backup/retore toevoeg:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:layout_gravity="center_vertical"
            android:gravity="center_vertical">

<LinearLayout android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="center_vertical"
              android:layout_gravity="center_vertical"
              android:padding="8dip">

    <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            card_view:cardElevation="3dp"
            card_view:cardCornerRadius="3dp"
            card_view:cardUseCompatPadding="true">

        <LinearLayout android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:orientation="vertical">

            <FrameLayout android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:padding="20dp">

                <TextView android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:text="@string/import_export_fragment__import"
                          android:textSize="20sp"/>

            </FrameLayout>

            <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/gray10"/>

            <LinearLayout android:id="@+id/import_sms"
                          android:clickable="true"
                          android:orientation="horizontal"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:gravity="center_vertical"
                          android:paddingTop="8dip"
                          android:paddingBottom="8dip"
                          android:layout_marginLeft="16dip"
                          android:layout_marginRight="16dip">

                <ImageView android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           android:layout_marginRight="10dip"
                           android:layout_marginEnd="10dip"
                           android:src="?import_sms"/>

                <LinearLayout android:orientation="vertical"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content">

                    <TextView android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:gravity="start"
                              style="@style/Registration.Description"
                              android:text="@string/import_fragment__import_system_sms_database"/>

                    <TextView android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:gravity="start"
                              android:textAppearance="?android:attr/textAppearanceSmall"
                              android:text="@string/import_fragment__import_the_database_from_the_default_system"/>

                </LinearLayout>
            </LinearLayout>

            <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/gray10"/>

            <LinearLayout android:id="@+id/import_plaintext_backup"
                          android:clickable="true"
                          android:orientation="horizontal"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:gravity="center_vertical"
                          android:paddingTop="8dip"
                          android:paddingBottom="8dip"
                          android:layout_marginLeft="16dip"
                          android:layout_marginRight="16dip">

                <ImageView android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           android:layout_marginRight="10dip"
                           android:layout_marginEnd="10dip"
                           android:src="?plaintext_backup"/>

                <LinearLayout android:orientation="vertical"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content">

                    <TextView android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:gravity="start"
                              style="@style/Registration.Description"
                              android:text="@string/import_fragment__import_plaintext_backup"/>

                    <TextView android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:gravity="start"
                              android:textAppearance="?android:attr/textAppearanceSmall"
                              android:text="@string/import_fragment__import_a_plaintext_backup_file"/>
                </LinearLayout>
            </LinearLayout>

            <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/gray10"/>

            <LinearLayout android:id="@+id/import_encrypted_backup"
                          android:clickable="true"
                          android:orientation="horizontal"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:gravity="center_vertical"
                          android:paddingTop="8dip"
                          android:paddingBottom="8dip"
                          android:layout_marginLeft="16dip"
                          android:layout_marginRight="16dip">

                <ImageView android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           android:layout_marginRight="10dip"
                           android:layout_marginEnd="10dip"
                           android:src="?encrypted_backup"/>

                <LinearLayout android:orientation="vertical"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content">

                    <TextView android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:gravity="start"
                              style="@style/Registration.Description"
                              android:text="@string/import_fragment__restore_encrypted_backup"/>

                    <TextView android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:gravity="start"
                              android:textAppearance="?android:attr/textAppearanceSmall"
                              android:text="@string/import_fragment__restore_a_previously_exported_encrypted_signal_backup"/>
                </LinearLayout>
            </LinearLayout>

        </LinearLayout>

    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
            android:layout_marginTop="20dp"
            card_view:cardElevation="3dp"
            card_view:cardCornerRadius="2dp"
            card_view:cardUseCompatPadding="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <LinearLayout android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:orientation="vertical">

            <FrameLayout android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:padding="20dp">

                <TextView android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:text="@string/import_export_fragment__export"
                          android:textSize="20sp"/>

            </FrameLayout>

            <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/gray10"/>

            <LinearLayout android:id="@+id/export_plaintext_backup"
                          android:clickable="true"
                          android:orientation="horizontal"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:gravity="center_vertical"
                          android:paddingTop="8dip"
                          android:paddingBottom="8dip"
                          android:layout_marginLeft="16dip"
                          android:layout_marginRight="16dip">

                <ImageView android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           android:layout_marginRight="10dip"
                           android:layout_marginEnd="10dip"
                           android:src="?plaintext_backup"/>

                <LinearLayout android:orientation="vertical"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content">

                    <TextView android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:gravity="start"
                              style="@style/Registration.Description"
                              android:text="@string/export_fragment__export_plaintext_backup"/>

                    <TextView android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:gravity="start"
                              android:textAppearance="?android:attr/textAppearanceSmall"
                              android:text="@string/export_fragment__export_a_plaintext_backup_compatible_with"/>
                </LinearLayout>
            </LinearLayout>

            <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/gray10"/>

            <LinearLayout android:id="@+id/export_encrypted_backup"
                          android:clickable="true"
                          android:orientation="horizontal"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:gravity="center_vertical"
                          android:paddingTop="8dip"
                          android:paddingBottom="8dip"
                          android:layout_marginLeft="16dip"
                          android:layout_marginRight="16dip">

                <ImageView android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           android:layout_marginRight="10dip"
                           android:layout_marginEnd="10dip"
                           android:src="?encrypted_backup"/>

                <LinearLayout android:orientation="vertical"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content">

                    <TextView android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:gravity="start"
                              style="@style/Registration.Description"
                              android:text="@string/export_fragment__export_encrypted_backup"/>


                    <TextView android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:gravity="start"
                              android:textAppearance="?android:attr/textAppearanceSmall"
                              android:text="@string/export_fragment__export_an_encrypted_backup_to_the_sd_card"/>
                </LinearLayout>
            </LinearLayout>

        </LinearLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>

Als ik dit zo gebruik valt op een toestel met lage schermresolutie de bovenste "Import" kop uit het beeld:
Afbeeldingslocatie: https://i.stack.imgur.com/vpBuP.jpg
Ik heb dit nu opgelost (met een vieze hack) door aan de bovenste cardview een atribuut android:layout_marginTop="160dp" mee te geven. Nu staat alles op het scherm, maar:
  1. Hoe hoger de schermresolutie, hoe lager de Import tag komt.
  2. Er ontstaat een grote overbodige witruimte aan de onderkant
Ik heb te weinig ervaring met deze opmaak onder Android, weet iemand waarom de originele opzet niet werkt en (mocht dat niet duidelijk zijn uit het eerste antwoord) hoe ik dit resolutie onafhankelijk mooi maak?

Acties:
  • +2 Henk 'm!

Verwijderd

Topicstarter
Ik heb het opgelost. Super simpel, zoals altijd achteraf: in de bovenste LinearLayout beide gravity elementen op top gezet:
code:
1
2
3
4
5
6
<LinearLayout android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="top"
              android:layout_gravity="top"
              android:padding="8dip">