0

私はAndroidの初心者であり、デフォルトの左上ではなく下/中央からプログラムでボタンを配置しようとすると問題が発生します。ボタンの下部に矢印があり、位置を矢印の先端に設定したい。どんな助けでも大歓迎です。

マイコード

popUpButton = (Button) findViewById(R.id.popUp);
    popUpButton.setOnClickListener(this); 

public void updateMsg(String t_info, float t_x, float t_y, int t_c){
     //infoView.updateInfo(t_info, t_x, t_y, t_c);
     popUpButton.setText(TouchView.touchInfo);       
     popUpButton.setX(t_x);
     popUpButton.setY(t_y);
}

XML

<RelativeLayout

<Button
    android:id="@+id/popUp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/balloon_overlay_bg_selector"
    android:text="Button"
    android:textColor="#000000"
    android:textSize="14dp" />


</RelativeLayout>

ここに画像の説明を入力

4

3 に答える 3

1

最善の方法は、y 座標を取得し、button.getheight を使用してボタンの高さを減算し、x 座標に対して同じことを行うことです。

于 2013-05-12T04:02:49.143 に答える