我有5个正方形的ImageButton,想要它们在屏幕底部依次排列。我已经为每一个ImageButton设置了不同的id:
<ImageButton
android:id="@+id/box1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:layout_weight="1"
android:layout_margin="1dp"
/>
我在Java的主文件中这样指定了背景:
int[] imageIds = new int[] {R.id.box1,R.id.box2,R.id.box3,R.id.box4,R.id.box5};
for(int i = 0; i<5; i++){
imageButtons[i] = (ImageButton) findViewById(imageIds[i]);
imageButtons[i].setBackgroundResource(R.drawable.blank);
}
我希望它能够自动缩放高度以匹配宽度,从而在屏幕底部整齐地并排显示(现在已经可以),但我不想使用setImageSource,因为这会在imagebutton周围添加边框。是否有可能实现这一点?