0

how to achieve this kind of gridlayoutは私が自動作成したい

がRecyclerViewを使用して上記の画像のようなグリッドレイアウトの列を調整アンドロイドRecyclerViewを使用してグリッドレイアウトを調整します。

最後に
+4

Googleで[Flexbox-layout](https://github.com/google/flexbox-layout)をご覧になるか、動作している場合はRecyclerViewでStaggeredGridLayoutManagerを試すことができます。 – ADM

+0

しかし、私はStaggeredGridLayoutManagerがこのような配置にはうまくいかないと思います。 Thx – ADM

+0

このチュートリアルを見ると、このトピックのチュートリアルがたくさんあります https://inducesmile.com/android/android-staggeredgridlayoutmanager-example-tutorial/ –

答えて

1

enter image description hereは、私が

/// Gradleのインポート/// コンパイル 'com.google.android:flexbox:0.3.1'

public class MainActivity extends AppCompatActivity { 

    List<String> list_text=new ArrayList<>(); 
    FlexboxLayout container; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     container=findViewById(R.id.v_container); 
     list_text.add("Avik"); 
     list_text.add("Rocky bolboa"); 
     list_text.add("Master"); 
     list_text.add("avhihsked"); 
     list_text.add("Prem chopra"); 
     list_text.add("Rambo"); 
     list_text.add("Piyali"); 
     list_text.add("Sheha Singh"); 
     list_text.add("Sheha Sarker"); 
     list_text.add("Supriya"); 
     list_text.add("Manish Singh"); 
     list_text.add("Chacha ji"); 
     list_text.add("DEbarun da"); 
     list_text.add("Asaduk da"); 
     list_text.add("Sunidhi chauhan"); 
     list_text.add("Shreya"); 
     list_text.add("Sourav mitra"); 

     inflatelayout(); 

    } 

    private void inflatelayout() { 
     LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
     buttonLayoutParams.setMargins(5,5,5,5); 
     for(int i=0;i<list_text.size();i++){ 
      final TextView tv = new TextView(getApplicationContext()); 
      tv.setText(list_text.get(i)); 
      tv.setHeight(100); 
      tv.setTextSize(16.0f); 
      tv.setGravity(Gravity.CENTER); 
      tv.setTextColor(Color.parseColor("#000000")); 
      tv.setBackground(getResources().getDrawable(R.drawable.rounded_corner_yellow)); 
      tv.setId(i + 1); 
      tv.setLayoutParams(buttonLayoutParams); 
      tv.setTag(i); 
      tv.setPadding(20, 10, 20, 10); 
      container.addView(tv); 
     } 

    } 
} 

FlexboxLayout

を使用してそれを行っています/////rounded_corner_yellow.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <stroke 
     android:width="1dp" 
     android:color="@color/colorAccent" /> 

    <solid android:color="@android:color/transparent" /> 

    <padding 
     android:left="10dp" 
     android:right="10dp" 
     android:top="3dp" /> 

    <corners android:radius="20dp" /> 
</shape> 

///////activity_main.xml//////

<?xml version="1.0" encoding="utf-8"?> 
<com.google.android.flexbox.FlexboxLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/v_container" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="16dp" 
    app:alignContent="stretch" 
    app:alignItems="stretch" 
    app:flexWrap="wrap"> 
</com.google.android.flexbox.FlexboxLayout> 
+0

こんにちは、@bhabin uは必要なものを手に入れます私のコードを使用して、私が言及したように余白の問題に直面している。その後、これを修正することができます私に知らせてください – avik

+0

私は[FlexBox](https://github.com/google/flexbox-layout)試してみてください –

+0

それは私に知らせる – avik

関連する問題