Android LinearLayout программно один столбец слева, один столбец с плавающей правой - PullRequest
0 голосов
/ 11 декабря 2018

Мой макет Android состоит из 2 TextView внутри LinearLayout.Однако я хочу, чтобы второе представление текста было выровнено по правому краю.

Объяснение:

enter image description here

// LinearLayout A
LinearLayout linearLayoutA = new LinearLayout(this);
linearLayoutA.setLayoutParams(new LinearLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
linearLayoutWorkoutPlansSessionsMain.addView(linearLayoutA);

// Title
TextView textViewExerciseTitle = new TextView(this);
textViewExerciseTitle.setText("Pull ups");
textViewExerciseTitle.setTextSize(16);
textViewExerciseTitle.setTextColor(Color.BLACK);
linearLayoutA.addView(textViewExerciseTitle);

// Reps & sets
TextView textViewSetsReps = new TextView(this);
textViewSetsReps.setText("8 x 4");
textViewSetsReps.setTextSize(16);
textViewSetsReps.setTextColor(Color.BLACK);
textViewSetsReps.setPadding(20,0,0,0);
linearLayoutA.addView(textViewSetsReps);

1 Ответ

0 голосов
/ 11 декабря 2018
TextView textViewSetsReps = new TextView(this);
    textViewSetsReps.setText("8 x 4");
    textViewSetsReps.setTextSize(16);
    textViewSetsReps.setTextColor(Color.BLACK);
    textViewSetsReps.setPadding(20,0,0,0);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT,  1.0f);
    textViewSetsReps.setLayoutParams(params);
    textViewSetsReps.setGravity(Gravity.RIGHT);
    ll.addView(textViewSetsReps);

Вы можете редактировать свой второй TextView, как это!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...