<分区>
我想在 Android
中设置 ImageView
的宽度和高度。 ImageView
在 XML
中不存在。它是在这里创建的:
public void setImageView(int i,Integer d, LinearLayout layout ) {
ImageView imageView = new ImageView(this);
imageView.setId(i);
imageView.setPadding(2, 2, 2, 2);
imageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), d));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
layout.addView(imageView);
}
并将其放入此 LinearLayout
中:
<HorizontalScrollView
android:id="@+id/horizontal_scroll_view"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:background="@drawable/white_lines"
android:layout_weight="15"
android:layout_height="0dp" >
<LinearLayout
android:id="@+id/scroll_view_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#999A9FA1"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
所以基本上我多次调用 setImageView
方法并用包含在 LinearLayouts
中的 ImageViews
填充我的 HorizontalScrollView
。我需要以 DP 而不是像素为单位设置此高度,以便它在所有设备上看起来都一样!!!