【发布时间】:2016-06-18 14:48:24
【问题描述】:
我想在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 方法并将HorizontalScrollView 填充为ImageViews 包含在LinearLayouts 中。我需要在 DP 而不是像素中设置这个高度,以便它在所有设备上看起来都一样!!!
【问题讨论】:
标签: java android xml android-layout imageview