@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View rowView = convertView;
    if (rowView == null) {
      LayoutInflater inflater =
          (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      rowView = inflater.inflate(R.layout.card_list_item, null);
    }

    CardView tv = (CardView) rowView.findViewById(R.id.card);
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) tv.getLayoutParams();
    Resources r = context.getResources();
    int px =
        (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, r.getDisplayMetrics());

    if (position == 0) {
      params.setMargins(px, px, px, px); // substitute parameters for left, top, right, bottom
      tv.setLayoutParams(params);
    } else {
      params.setMargins(px, 0, px, px);
      tv.setLayoutParams(params);
    }

    ImageView image = (ImageView) rowView.findViewById(R.id.line_img);
    TextView line = (TextView) rowView.findViewById(R.id.line_name);

    if (position == 0) {
      image.setColorFilter(Color.argb(89, 198, 12, 48));
    } else if (position == 1) {
      image.setColorFilter(Color.argb(89, 0, 161, 222));
    } else if (position == 2) {
      image.setColorFilter(Color.argb(170, 98, 54, 27));
    } else if (position == 3) {
      image.setColorFilter(Color.argb(89, 0, 155, 58));
    } else if (position == 4) {
      image.setColorFilter(Color.argb(117, 249, 70, 28));
    } else if (position == 5) {
      image.setColorFilter(Color.argb(137, 82, 35, 152));
    } else if (position == 6) {
      image.setColorFilter(Color.argb(150, 226, 126, 166));
    } else if (position == 7) {
      image.setColorFilter(Color.argb(89, 249, 227, 0));
    } else {
      image.setColorFilter(Color.argb(0, 255, 255, 255));
    }
    image.setImageResource(images[position]);

    line.setText(lines[position]);
    line.setTextColor(Color.BLACK);

    return rowView;
  }
Beispiel #2
0
  private void setUpCardView() {
    LayoutParams params = new LayoutParams(mCardView.getLayoutParams());
    params.topMargin = mMarginTop;
    params.bottomMargin = mMarginBottom;
    params.leftMargin = mMarginLeft;
    params.rightMargin = mMarginRight;

    mCardView.setLayoutParams(params);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTitle("Impostazioni");
    getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    LinearLayout container = new LinearLayout(this);
    container.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    container.setOrientation(LinearLayout.VERTICAL);

    NestedScrollView scrollView = new NestedScrollView(this);
    scrollView.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    scrollView.addView(container);

    headers = new ArrayList();
    onInit();

    // Start parsing and creating the layout
    for (SettingHeader header : headers) {
      CardView headerCard =
          (CardView) LayoutInflater.from(this).inflate(R.layout.settings_header, null);
      LinearLayout.LayoutParams params =
          new LinearLayout.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      params.setMargins(0, 0, 0, 10);
      headerCard.setLayoutParams(params);

      TextView headerTitle = (TextView) headerCard.findViewById(R.id.headerTitle);
      StaticHeightListView inputsContainer =
          (StaticHeightListView) headerCard.findViewById(R.id.inputContainer);

      headerTitle.setText(header.title);

      inputsContainer.setAdapter(new SettingInputAdapter(this, header.inputs));

      container.addView(headerCard);
    }

    setContentView(scrollView);
  }