Je souhaite créer une application qui générera plusieurs textos qui s'intégreront tous dans la mise en page désignée. mais une fois que la ligne est complète au lieu de continuer dans la nouvelle ligne ne montrent pas le reste des textviewsDisposition linéaire n'utilisant pas toutes les lignes
mon MainActivity.java:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<String> urls=new ArrayList<String>(); //to read each line
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.sell);
// Add textview 1
for (int i=0;i<10;i++){
LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams1.setMargins(10, 10, 10, 10);
TextView textView1 = new TextView(this);
textView1.setLayoutParams(layoutParams1);
textView1.setText("TextView1\n2");
textView1.setBackgroundColor(0xFF3EB427); // hex color 0xAARRGGBB
textView1.setPadding(10, 10, 10, 10);// in pixels (left, top, right, bottom)
linearLayout.addView(textView1);
}
LinearLayout linearLayout2 = (LinearLayout) findViewById(R.id.buy);
LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
for (int i=0;i<2;i++){
layoutParams2.setMargins(10, 10, 10, 10);
TextView textView1 = new TextView(this);
textView1.setLayoutParams(layoutParams2);
textView1.setText("TextView2");
textView1.setBackgroundColor(0xFFB60612); // hex color 0xAARRGGBB
textView1.setPadding(20, 20, 20, 20);// in pixels (left, top, right, bottom)
linearLayout2.addView(textView1);
}
}
}
mon xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent"
android:id="@+id/mymain"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ohad.tradertracker.MainActivity"
android:weightSum="1">
<LinearLayout
android:id="@+id/stats"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="101dp">
</LinearLayout>
<LinearLayout
android:id="@+id/sell"
android:layout_weight=".5"
android:fillViewport="true"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
Comment puis-je générer une quantité inconnue de textview et utiliser toute la taille de la mise en page ???
Ceci est double question posibble [Check] (https://stackoverflow.com/q/2827079/6099173). Si ce n'est pas votre question, cochez-la [This!] (Https://stackoverflow.com/a/31855704/6099173) –
Le gonflement de la mise en page à partir de Java serait une mauvaise performance si le nombre de contenus augmente. RecyclerView est la méthode recommandée. Je ne sais pas à qui appartient ce blog, mais je pense assez pour commencer. https://android--code.blogspot.com/2015/12/android-recyclerview-grid-layout-example.html Officiel: https://developer.android.com/training/material/lists-cards .html? hl = ja – neonankiti