0

你如何修复(防止它们移动)android中表格布局中单元格的大小?

我在每个单元格内都有一个带有图像按钮的表格布局,问题是,当我更改(或删除)图像时,按钮的大小会发生变化。我该如何防止这种情况?

4

2 回答 2

2

您可以使用属性 setMinimum Width/height 和 Maximum width/height 来避免这种情况

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minWidth="100dp"
    android:maxWidth="200dp"
    android:minHeight="100dp"
    android:maxHeight="200dp"
    android:src="@drawable/ic_launcher" />

这肯定会帮助您完成工作。

谢谢

这可以帮助您以编程方式调整 ImageButton,同时检测不同的屏幕尺寸(小、中、大、超大)

//Determine screen size
    if ((getResources().getConfiguration().screenLayout &      Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {     
        Toast.makeText(this, "Large screen",Toast.LENGTH_LONG).show();

    }
    else if ((getResources().getConfiguration().screenLayout &      Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {     
        Toast.makeText(this, "Normal sized screen" , Toast.LENGTH_LONG).show();

    } 
    else if ((getResources().getConfiguration().screenLayout &      Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {     
        Toast.makeText(this, "Small sized screen" , Toast.LENGTH_LONG).show();
    }
    else {
        Toast.makeText(this, "Screen size is neither large, normal or small" , Toast.LENGTH_LONG).show();
    }




    //Determine density
    DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        int density = metrics.densityDpi;

        if (density==DisplayMetrics.DENSITY_HIGH) {
            Toast.makeText(this, "DENSITY_HIGH... Density is " + String.valueOf(density),  Toast.LENGTH_LONG).show();
        }
        else if (density==DisplayMetrics.DENSITY_MEDIUM) {
            Toast.makeText(this, "DENSITY_MEDIUM... Density is " + String.valueOf(density),  Toast.LENGTH_LONG).show();
        }
        else if (density==DisplayMetrics.DENSITY_LOW) {
            Toast.makeText(this, "DENSITY_LOW... Density is " + String.valueOf(density),  Toast.LENGTH_LONG).show();
        }
        else {
            Toast.makeText(this, "Density is neither HIGH, MEDIUM OR LOW.  Density is " + String.valueOf(density),  Toast.LENGTH_LONG).show();
        }
于 2012-07-18T09:45:49.070 回答
1

将每个 View 的 layout_width 设置为 0。根据需要在每个 View 中添加 layout_weight

参考: http: //pournaras.zilsen.com/2010/11/01/fixed-column-width-in-tablelayout/

于 2012-07-18T09:45:33.677 回答