在 Horizo​​ntalScrollView 内的 LinearLayout 中添加按钮之间的间距

Add spacing between buttons in LinearLayout that's inside a HorizontalScrollView

我试图更改按钮的 X 位置,它起作用了,但按钮最终被 Horizo​​ntalScrollView 卡住了。我只想在按钮之间添加间距。

这是我用来以编程方式显示按钮的代码:

@TargetApi(21)
private void loadProfiles() {
    HorizontalScrollView scrollView = (HorizontalScrollView) findViewById(R.id.horizontalScrollView);
    LinearLayout layout = (LinearLayout) scrollView.findViewById(R.id.scrollLinear);
    if(getFilesDir().listFiles().length != 0) {
        for(File file : getFilesDir().listFiles()) {
            ImageButton button = new ImageButton(this);
            button.setLayoutParams(new ActionBar.LayoutParams(150, 150));
            button.setY(35);
            button.setBackground(getResources().getDrawable(R.drawable.roundedbutton, getTheme()));
            layout.addView(button);
        }
    }
}

这是 Horizo​​ntalScrollView:

<HorizontalScrollView
    android:layout_width="fill_parent"
    android:layout_height="100dp"
    android:background="@drawable/bar"
    android:id="@+id/horizontalScrollView"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" >

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scrollLinear"></LinearLayout>
</HorizontalScrollView>

这是按钮当前外观的图片:

Picture

ImageButton button = new ImageButton(this);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(150, 150);
        layoutParams.setMargins(10,0,0,10);
        button.setLayoutParams(layoutParams);
        button.setY(35);
        button.setBackground(getResources().getDrawable(R.drawable.roundedbutton, getTheme()));
        layout.addView(button);

这应该有效