0

我什至试图在 AlertDialog 中获取我的按钮。目前,一个按钮的文本进入第二行,使该按钮比其他两个稍大。这是我的对话框(不在片段中,只是在活动中)

public void imageActions(final View v, final int position) {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Image Actions");
    alert.setIcon(R.drawable.image_icon);
    alert.setNeutralButton("View Image", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
              seeImage(v,position);
        } });   
    alert.setPositiveButton("Remove Image", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
              sureToDelte(v,position);
        } });       
    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {  
        } }); 
    alert.show();           
}

我尝试在之后添加此代码,alert.show();但它导致了崩溃。

Button positive = (Button) findViewById(android.R.id.button1);
positive.setLayoutParams(new LinearLayout.LayoutParams(10, 10));
Button negative = (Button) findViewById(android.R.id.button2);
negative.setLayoutParams(new LinearLayout.LayoutParams(10, 10));
Button neutral = (Button) findViewById(android.R.id.button3);
neutral.setLayoutParams(new LinearLayout.LayoutParams(10, 10));
4

1 回答 1

0

最好编辑您的 XML 文件,您可以执行以下操作:

<LinearLayout
        android:id="@+id/activity_content"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

            <Button
                android:id="@+id/buttonID1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Your Button" />
            <Button
                android:id="@+id/buttonID2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Your Button" />
</LinearLayout>

否则,如果您真的想以编程方式对其进行编辑,请使用 LinearLayout 属性,例如:

LinearLayout layout = (LinearLayout) findViewById(R.id.your_linear);
LayoutParams params = layout.getLayoutParams(); // Params
params.width = params.FILL_PARENT; // Fill the space horizontally
params.height = params.WRAP_CONTENT; // Fill the space vertically but "automatically", depends on the object's size.
于 2013-03-30T23:43:26.227 回答