我想在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而不是像素,以便在所有设备上看起来都一样!!!