Bonjour à tous,
J'ai une petite application qui mémorise nos humeurs au fil des jours et les affiches dans une MoodHistoryActivity pour les 7 dernier jours,
J'ai un petit soucis d'affichage au niveau du layout,
Je m'explique :
J'ai crée 7 RelativeLayouts dans un LinearLayout (Un pour chaque jour dans l'historique) disposé les uns en dessous des autres.
La dernière humeur est sauvegardée automatiquement à chaque fois dans les prefs, et affichée directement dans le layout Hier de l'historique (case la plus basse)
Le soucis est le suivant :
Le linearLayout contenant les 7 dernières humeurs est comme "écrasé" sur les cotés et on ne voit plus que 4 cases sur 7... Chaque case prennant beaucoup trop de place que programmé dans le fichier layout et les 3 premiers jours sont hors-champ
Ce problème d'affichage arrive sur mon téléphone et aussi sur émulateur
Voici le code xml:
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/light_grey" tools:context=".controllers.MoodHistoryActivity"> <RelativeLayout android:id="@+id/activity_historic_day_seven" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <TextView android:id="@+id/activity_historic_text_seven" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_marginStart="5dp" tools:text="@string/day_7" android:textStyle="bold"/> <Button android:id="@+id/activity_historic_btn_seven" android:visibility="gone" android:layout_width="20dp" android:layout_height="20dp" android:layout_alignParentEnd="true" android:layout_centerVertical="true" android:layout_marginEnd="20dp" android:background="@drawable/ic_comment_black_48px"/> </RelativeLayout> <RelativeLayout android:id="@+id/activity_historic_day_six" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <TextView android:id="@+id/activity_historic_text_six" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_marginStart="5dp" tools:text="@string/day_6" android:textStyle="bold"/> <Button android:id="@+id/activity_historic_btn_six" android:visibility="gone" android:layout_width="20dp" android:layout_height="20dp" android:layout_alignParentEnd="true" android:layout_centerVertical="true" android:layout_marginEnd="20dp" android:background="@drawable/ic_comment_black_48px"/> </RelativeLayout> <RelativeLayout android:id="@+id/activity_historic_day_five" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <TextView android:id="@+id/activity_historic_text_five" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_marginStart="5dp" tools:text="@string/day_5" android:textStyle="bold"/> <Button android:id="@+id/activity_historic_btn_five" android:visibility="gone" android:layout_width="20dp" android:layout_height="20dp" android:layout_alignParentEnd="true" android:layout_centerVertical="true" android:layout_marginEnd="20dp" android:background="@drawable/ic_comment_black_48px"/> </RelativeLayout> <RelativeLayout android:id="@+id/activity_historic_day_four" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <TextView android:id="@+id/activity_historic_text_four" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_marginStart="5dp" tools:text="@string/day_4" android:textStyle="bold"/> <Button android:id="@+id/activity_historic_btn_four" android:visibility="gone" android:layout_width="20dp" android:layout_height="20dp" android:layout_alignParentEnd="true" android:layout_centerVertical="true" android:layout_marginEnd="20dp" android:background="@drawable/ic_comment_black_48px"/> </RelativeLayout> <RelativeLayout android:id="@+id/activity_historic_day_three" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <TextView android:id="@+id/activity_historic_text_three" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_marginStart="5dp" tools:text="@string/day_3" android:textStyle="bold"/> <Button android:id="@+id/activity_historic_btn_three" android:visibility="gone" android:layout_width="20dp" android:layout_height="20dp" android:layout_alignParentEnd="true" android:layout_centerVertical="true" android:layout_marginEnd="20dp" android:background="@drawable/ic_comment_black_48px"/> </RelativeLayout> <RelativeLayout android:id="@+id/activity_historic_day_two" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <TextView android:id="@+id/activity_historic_text_two" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_marginStart="5dp" tools:text="@string/day_2" android:textStyle="bold"/> <Button android:id="@+id/activity_historic_btn_two" android:visibility="gone" android:layout_width="20dp" android:layout_height="20dp" android:layout_alignParentEnd="true" android:layout_centerVertical="true" android:layout_marginEnd="20dp" android:background="@drawable/ic_comment_black_48px"/> </RelativeLayout> <RelativeLayout android:id="@+id/activity_historic_day_one" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <TextView android:id="@+id/activity_historic_text_one" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_marginStart="5dp" tools:text="@string/day_1" android:textStyle="bold"/> <Button android:id="@+id/activity_historic_btn_one" android:visibility="gone" android:layout_width="20dp" android:layout_height="20dp" android:layout_alignParentEnd="true" android:layout_centerVertical="true" android:layout_marginEnd="20dp" android:background="@drawable/ic_comment_black_48px"/> </RelativeLayout> </LinearLayout>
Voici le code Java :
Je pense que le soucis vient du Switch de displayMood mais je ne sais pas ce qui cloche...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public class MoodHistoryActivity extends AppCompatActivity { private int mood; private SharedPreferences mPreferences; public static final String PREF_KEY_CURRENT_SMILEY = "PREF_KEY_CURRENT_SMILEY"; public static final String PREF_KEY = "PREF_KEY"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mood_history); mPreferences = getApplicationContext().getSharedPreferences(PREF_KEY, 0); //0 for private mode RelativeLayout mDayOne = findViewById(R.id.activity_historic_day_one); RelativeLayout mDayTwo = findViewById(R.id.activity_historic_day_two); RelativeLayout mDayThree = findViewById(R.id.activity_historic_day_three); RelativeLayout mDayFour = findViewById(R.id.activity_historic_day_four); RelativeLayout mDayFive = findViewById(R.id.activity_historic_day_five); RelativeLayout mDaySix = findViewById(R.id.activity_historic_day_six); RelativeLayout mDaySeven = findViewById(R.id.activity_historic_day_seven); /* Button mButtonOne = findViewById(R.id.activity_historic_btn_one); Button mButtonTwo = findViewById(R.id.activity_historic_btn_two); Button mButtonThree = findViewById(R.id.activity_historic_btn_three); Button mButtonFour = findViewById(R.id.activity_historic_btn_four); Button mButtonFive = findViewById(R.id.activity_historic_btn_five); Button mButtonSix = findViewById(R.id.activity_historic_btn_six); Button mButtonSeven = findViewById(R.id.activity_historic_btn_seven); */ TextView mTextViewOne = findViewById(R.id.activity_historic_text_one); TextView mTextViewTwo = findViewById(R.id.activity_historic_text_two); TextView mTextViewThree = findViewById(R.id.activity_historic_text_three); TextView mTextViewFour = findViewById(R.id.activity_historic_text_four); TextView mTextViewFive = findViewById(R.id.activity_historic_text_five); TextView mTextViewSix = findViewById(R.id.activity_historic_text_six); TextView mTextViewSeven = findViewById(R.id.activity_historic_text_seven); mTextViewOne.setText(getString(R.string.day_1)); mTextViewTwo.setText(getString(R.string.day_2)); mTextViewThree.setText(getString(R.string.day_3)); mTextViewFour.setText(getString(R.string.day_4)); mTextViewFive.setText(getString(R.string.day_5)); mTextViewSix.setText(getString(R.string.day_6)); mTextViewSeven.setText(getString(R.string.day_7)); //Instancied WorkRequest PeriodicWorkRequest saveMood = new PeriodicWorkRequest.Builder(SaveMoodWorker.class, 1, TimeUnit.MINUTES).build(); //Queue the work WorkManager.getInstance().enqueue(saveMood); RelativeLayout[] layouts = {mDayOne, mDayTwo, mDayThree, mDayFour, mDayFive, mDaySix, mDaySeven}; // Button[] buttons = {mButtonOne, mButtonTwo, mButtonThree, mButtonFour, mButtonFive, mButtonSix, mButtonSeven}; // Loop to display last 7 moods for (int i = 0; i < 1; i++) { this.displayMood(layouts[i]); } } public void displayMood(RelativeLayout relativeLayout) { // Change the width of the layout Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); try { display.getRealSize(size); } catch (NoSuchMethodError err) { display.getSize(size); } int width = size.x; int height = size.y; mood = mPreferences.getInt(PREF_KEY_CURRENT_SMILEY,8); // If no mood, layout is still blank if (mood == 8) { relativeLayout.setBackgroundColor(0); } else { // Set background color and fraction for each mood case switch (mood) { case 0: relativeLayout.setLayoutParams(new LinearLayout.LayoutParams(width / 5, LinearLayout.LayoutParams.WRAP_CONTENT, 1)); relativeLayout.setBackgroundColor(getResources().getColor(R.color.faded_red)); break; case 1: relativeLayout.setLayoutParams(new LinearLayout.LayoutParams((width / 5) * 2, LinearLayout.LayoutParams.MATCH_PARENT, 1)); relativeLayout.setBackgroundColor(getResources().getColor(R.color.warm_grey)); break; case 2: relativeLayout.setLayoutParams(new LinearLayout.LayoutParams((width / 5) * 3, LinearLayout.LayoutParams.MATCH_PARENT, 1)); relativeLayout.setBackgroundColor(getResources().getColor(R.color.cornflower_blue_65)); break; case 3: relativeLayout.setLayoutParams(new LinearLayout.LayoutParams((width / 5) * 4, LinearLayout.LayoutParams.MATCH_PARENT, 1)); relativeLayout.setBackgroundColor(getResources().getColor(R.color.light_sage)); break; case 4: relativeLayout.setLayoutParams(new LinearLayout.LayoutParams(width, LinearLayout.LayoutParams.MATCH_PARENT, 1)); relativeLayout.setBackgroundColor(getResources().getColor(R.color.banana_yellow)); break; } } }
Merci d'avance,
Matteo
Partager