<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/randomImage"
android:gravity="center_horizontal|bottom"
/>
特别是我在询问这两个属性:
android:drawableTop="@drawable/randomImage"
android:gravity="center_horizontal|bottom"
按钮的外观如下:
按钮使用静态xml完成。
最后,我必须回答我的问题:
android:gravity="center_horizontal|bottom"
记者:
setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM);
和
android:drawableTop="@drawable/randomImage"
记者:
setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom);
答案 0 :(得分:1)
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) {
}
});