public void makeCard( Context context, View view, String time, String startpt1, String startpt2, String endpt1, String endpt2)
{
    CardView card = new CardView(context);
    LinearLayout ll = view.findViewById(R.id.rides);
    // Set the CardView layoutParams
    int w = getResources().getDimensionPixelSize(R.dimen._270sdp);
    int h = getResources().getDimensionPixelSize(R.dimen._120sdp);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(w, h);
    card.setForegroundGravity(17);
    card.setLayoutParams(params);
    card.setRadius(60);
    card.setCardElevation(60);
    Typeface latoregular = getResources().getFont(R.font.latoregular);
    Typeface latobold = getResources().getFont(R.font.latobold);
    // Initialize a new TextView to put in CardView
    TextView tv = new TextView(context);
    tv.setLayoutParams(params);
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    try {
        Date date = format.parse(time);
        tv.setText(date.toString());
        Log.d("ASD", String.valueOf(date));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    tv.setTextSize(14);
    tv.setPadding(60,40,0,0);
    tv.setTextColor(Color.parseColor("#1fb286"));
    tv.setTypeface(latobold);
    tv.setTypeface(tv.getTypeface(), Typeface.BOLD);
    card.addView(tv);
    ll.addView(card);
}
This cardview hugs the side, and no matter what I change about the layout gravity, the card does not move. I can set the padding on the left to make it seem centered, but on different sized screens it would not be perfectly centered

 
     
    