簡體   English   中英

Android LinearLayout以編程方式向左移一列,向右浮動一列

[英]Android LinearLayout programmatically one column left, one column float right

我的Android布局在LinearLayout中包含2個TextView。 但是,我希望第二個文本視圖正確對齊。

說明:

在此處輸入圖片說明

// 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);
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!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM