private void createLeaderboardEntry(DocumentSnapshot document, LinearLayout…
- User
private void createLeaderboardEntry(DocumentSnapshot document, LinearLayout leaderboardLayout, int rank, boolean highlight) { TextView scoreView = new TextView(this); String nickname = document.getString("nickname"); String score = document.getLong("score").toString(); String text = rank > 0 ? rank + ". " : ""; // Add rank number if provided text += nickname != null ? nickname + " " + score : "Anonymous " + score;
scoreView.setText(text); scoreView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); scoreView.setGravity(Gravity.CENTER_HORIZONTAL); if (highlight) { // Highlight the current user; for example, by changing the text color scoreView.setTextColor(ContextCompat.getColor(this, R.color.highlight_color)); scoreView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24); }I want a bigger margin around the highlighted text
- Assistant
To increase the margin around the highlighted
TextView(scoreView), you can set itsLayoutParamsto include the desired margins. You can do so by creating a set ofLinearLayout.LayoutParamswith the required margins and setting them to theTextView. Below is the code example modified to include a bigger margin for the highlightedTextView:// ... if (highlight) { // Highlight the current user; for example, by changing the text color scoreView.setTextColor(ContextCompat.getColor(this, R.color.highlight_color)); scoreView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24); // Define margin in pixels (you can adjust these values to suit your needs) int marginInDp = 16; // For example, 16dp int marginInPx = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, marginInDp, getResources().getDisplayMetrics()); // Create LinearLayout.LayoutParams with margins LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT ); layoutParams.setMargins(marginInPx, marginInPx, marginInPx, marginInPx); // Apply margins to all sides (left, top, right, bottom) // Set the layout parameters to the TextView scoreView.setLayoutParams(layoutParams); } // Add this TextView to the parent layout leaderboardLayout.addView(scoreView); // ...