Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
这个静态按钮可以用java代码完成吗?_Java_Android_Button - Fatal编程技术网

这个静态按钮可以用java代码完成吗?

这个静态按钮可以用java代码完成吗?,java,android,button,Java,Android,Button,这是按钮的外观: 按钮是用静态xml完成的 最后,我要回答我的问题: android:drawableTop="@drawable/randomImage" android:gravity="center_horizontal|bottom" 通讯员: android:gravity="center_horizontal|bottom" android:drawableTop="@drawable/randomImage" 及 通讯员: android:gravity="center_h

这是按钮的外观:

按钮是用静态xml完成的

最后,我要回答我的问题:

android:drawableTop="@drawable/randomImage"
android:gravity="center_horizontal|bottom"
通讯员:

android:gravity="center_horizontal|bottom"
android:drawableTop="@drawable/randomImage"

通讯员:

android:gravity="center_horizontal|bottom"
android:drawableTop="@drawable/randomImage"

如何设置重心,使其同时处于
水平中心|底部
。我看到有一种方法
Button.setGravity(Gravity.CENTER\u HORIZONTAL)
Button.setGravity(Gravity.BOTTOM)
,但如何应用这两种方法。还有怎么做呢?
android:drawableTop=“@drawable/randomage”
我应该附上一张按钮显示方式的图片。关于
android:drawableTop=“@drawable/randomage”
?实际上你是不对的!我改变了你的答案
setGravity(重力。重心水平|重力。底部)setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom);
  Button mButton_dial = null;
     mButton_dial = new Button(this);
    mButton_dial.setText("Dial!");

    mLinearLayout_no_button = new LinearLayout(this);

    mLinearLayout_no_button.addView(mButton_dial);
    mButton_dial.setGravity(20);

    mButton_dial.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {

      }
    });