[英]How to align a button to bottom of screen
我已经在WebView中添加了一个按钮。 但是我无法使其对准屏幕底部。 我给了下面的代码。
Button button = new Button(context);
button.setText("Button");
LayoutParams params1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
button.setLayoutParams(params1);
webView.addView(button);
有谁知道如何做到这一点。
为了您的关心,请尝试这样:;
Button btn1 = (Button) findViewById(R.id.btn1);
btn1.setGravity(Gravity.BOTTOM);
更新::尝试将U放在屏幕底部的按钮进行此类操作
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical" >
<Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="3" />
</LinearLayout>
您可以尝试使用LinearLayout和重力:
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.gravity=Gravity.BOTTOM;
好的,我找到了解决方案。 我做了button.setY(screenHeight-button.getHeight());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.