我有 5 个方形 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 周围放置一个边框。