在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應用中設置底部按鈕。