我在xml中创建HorizontalScrollView
并以编程方式插入图像,但我的边距有问题。如何为HorizontalScrollView
中的图像设置水平边距?以下是我的代码:
xml:
<HorizontalScrollView
android:id="@+id/HorizontalScrollView"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp">
<LinearLayout
android:id="@+id/innerLay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!--Image Views here -->
</LinearLayout>
</HorizontalScrollView>
java:
ImageView imageView = new ImageView(getActivity());
scrollLinearLayout.addView(imageView);
//set height and other image properties.
答案 0 :(得分:0)
使用此功能设置运行时边距以查看
public static void setMargins (View v, int left, int top, int right, int bottom) {
if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
p.setMargins(left, top, right, bottom);
v.requestLayout();
}
}