Bonjour à tous,
je commence tout juste a apprendre à programmer une application. Je suis donc très très nul. J'ai des bases en programmation (surtout en algo).
J'ai commencé par faire mon layout en définissant le cadre que je voudrais :
Sauf que je voudrais générer dynamiquement les 3 textes 2.x (car il y en aura pas forcement 3).
Je voudrais aussi qu'ils soient répartis de manière harmonieuse dans le sous layout.
Ca semble bien marcher mais comment bien répartir les textview ?
Pour détailler un peu : mon but est d'écrire une phrase du style "2x + 3y - 5x + 2x²"
L'utilisateur pourra ensuite cliquer sur 2x ou +3y ou -5x ou +2x²
Merci d'avance pour votre aide.
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 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="20dp" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="150dp" android:layout_margin="10dp" android:text="texte de test X" android:textSize="20dp" android:textAlignment="center"/> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:layout_margin="20dp" android:orientation="horizontal" android:layout_gravity="center" android:id="@+id/layoutProp"> </LinearLayout> </LinearLayout> </LinearLayout>
Code Java : 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 package fr.haydens.maths_calcullitteral_reduire; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private LinearLayout myLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.myLayout= (LinearLayout) findViewById(R.id.layoutProp); int nbTextView=3; for(int i=0; i<3; i++) { TextView text = new TextView(this); text.setText("2." + i+1); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT ); myLayout.addView(text); } } }
Partager