I have a class that I am building programmatically and I need to adjust the 2 button layout to look like the other classes I have.
In this class AttributeWizard I'm doing through code, because I do database manipulation and I need to build the GUI like this.
I want to adjust the layout of the buttons (layoutButtons) to fit the full width of the screen. Currently they do not fill the entire space.
public class AttributeWizard extends Activity {
private LinearLayout linearLayoutAttribute;
private LinearLayout layoutBotoes;
private Button bNext;
private Button bPrev;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_uisarde_attributes);
linearLayoutAttribute = findViewById(R.id.linearLayoutAttribute);
createLayoutForButtons();
linearLayoutAttribute.addView(layoutBotoes);
layoutBotoes.getLayoutParams().height = LinearLayout.LayoutParams.FILL_PARENT;
layoutBotoes.getLayoutParams().width = LinearLayout.LayoutParams.MATCH_PARENT;
}
public void createLayoutForButtons() {
layoutBotoes = new LinearLayout(AttributeWizard.this);
bNext = new Button(AttributeWizard.this);
bNext.setText("Próximo");
bPrev = new Button(AttributeWizard.this);
bPrev.setText("Anterior");
layoutBotoes.setOrientation(LinearLayout.HORIZONTAL);
layoutBotoes.addView(bPrev);
layoutBotoes.addView(bNext);
}
}
The activity_uisarde_percurso.xml layout file goes as an example to see how I want the buttons to be at the bottom (if anyone knows how to remove the tab between them, thank you)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
style="?android:textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Seleção de percurso"
android:textStyle="bold" />
<TextView
android:id="@+id/tvInfoProperty"
style="?android:textAppearanceSmall"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/inst_percurso" />
<RadioGroup
android:id="@+id/rgPercurso"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp" >
<RadioButton
android:id="@+id/rbPadrao"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Padrão" />
<RadioButton
android:id="@+id/rbPersonalizado"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Personalizado" />
</RadioGroup>
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:gravity="bottom"
android:orientation="horizontal">
<Button
android:id="@+id/prev_button_percurso"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selectable_item_background"
android:text="@string/prev" />
<Button
android:id="@+id/next_button_percurso"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selectable_item_background"
android:text="@string/next" />
</LinearLayout>
</LinearLayout>
When should I change properties? After adding to the main layout? Before? Am I setting the right property?