Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
630 B
1
Indexable
Never
TextView textView = new TextView(this);
textView.setText("Hello, World!");

// Define the layout parameters
ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(
        ViewGroup.LayoutParams.WRAP_CONTENT,
        ViewGroup.LayoutParams.WRAP_CONTENT
);

// Set the margins (left, top, right, bottom)
params.setMargins(16, 16, 16, 16); // in pixels, you may want to convert dp to px

// Apply the parameters to the TextView
textView.setLayoutParams(params);

// Add the TextView to the layout (e.g., LinearLayout or RelativeLayout)
LinearLayout layout = findViewById(R.id.your_layout);
layout.addView(textView);
Leave a Comment