document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package com.codingrakitan.homegrab;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.graphics.Typeface;
  6. import android.os.Bundle;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.widget.LinearLayout;
  10. import android.widget.TextView;
  11.  
  12. import com.androidnetworking.widget.ANImageView;
  13.  
  14. public class MainActivity extends AppCompatActivity {
  15.  
  16. private LayoutInflater inf;
  17. private LinearLayout root;
  18. @Override
  19. protected void onCreate(Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.activity_main);
  22. root = findViewById(R.id.root);
  23. inf = getLayoutInflater();
  24. String[] s = getResources().getStringArray(R.array.judul);
  25. String[] s2 = getResources().getStringArray(R.array.des);
  26. String[] gm = getResources().getStringArray(R.array.gambar);
  27. int no = 0;
  28. LinearLayout ll = new LinearLayout(this);
  29. for (int i =0;i<s.length;i++){
  30. no++;
  31. if (no==1){
  32. LinearLayout ly = BuatLinearLayout();
  33. ll = ly;
  34. }
  35.  
  36. if (no==2){
  37. no =0;
  38. }
  39.  
  40. BuatCard(s[i], s2[i], ll, gm[i], no);
  41.  
  42.  
  43. }
  44. }
  45.  
  46. private LinearLayout BuatLinearLayout() {
  47. LinearLayout ly = new LinearLayout(this);
  48. LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  49. ly.setLayoutParams(lp);
  50. ly.setOrientation(LinearLayout.HORIZONTAL);
  51. root.addView(ly);
  52. return ly;
  53. }
  54.  
  55.  
  56. private void BuatCard(String judul, String des, LinearLayout ly, String url_gm, int no) {
  57. View v = inf.inflate(R.layout.card, null);
  58. TextView j = v.findViewById(R.id.textView);
  59. TextView j2 = v.findViewById(R.id.textView2);
  60. ANImageView image = v.findViewById(R.id.gm);
  61. Typeface typeface = Typeface.createFromAsset(getAssets(), "font/arial.ttf");
  62. j.setTypeface(typeface);
  63. j.setText(judul);
  64. j2.setText(des);
  65.  
  66. image.setImageUrl(url_gm);
  67. LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
  68. LinearLayout.LayoutParams.MATCH_PARENT,
  69. LinearLayout.LayoutParams.MATCH_PARENT,
  70. 1.0f);
  71. if(no==1){
  72. lp.setMargins(30, 20,20, 30);
  73. }else{
  74. lp.setMargins(20, 20,30, 30);
  75. }
  76.  
  77. v.setLayoutParams(lp);
  78. ly.addView(v);
  79.  
  80.  
  81. }
  82. }
');