在Android中,可以通过布局文件或者代码来设置底部按钮。以下是两种常见的方法:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2" />
</LinearLayout>
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setGravity(Gravity.BOTTOM);
Button button1 = new Button(this);
button1.setText("Button 1");
Button button2 = new Button(this);
button2.setText("Button 2");
layout.addView(button1);
layout.addView(button2);
// 将底部按钮添加到布局中
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layout.setLayoutParams(layoutParams);
RelativeLayout mainLayout = findViewById(R.id.main_layout);
mainLayout.addView(layout);
通过以上方法,可以实现在Android应用中设置底部按钮。