【发布时间】:2017-03-09 10:03:59
【问题描述】:
我在 LinearLayout 中动态添加 ImageViews,女巫在 HorizontalScrollView 内。
现在我想根据这个HorizontalScrollView的父LinearLayout来设置这些ImageView的宽高。
这是我的 xml (information_imagescrollview_item.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parentlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<HorizontalScrollView
android:id="@+id/horizontal_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linear"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
这是我的代码:
View contentView = inflater.inflate(R.layout.information_imagescrollview_item, container, false);
LinearLayout scrollViewLayout = (LinearLayout) contentView.findViewById(R.id.linear);
for(Object intObj : page.content) {
ImageView imageView = new ImageView(this.getContext());
Drawable myDrawable = getResources().getDrawable((int) intObj);
imageView.setImageDrawable(myDrawable);
scrollViewLayout.addView(imageView);
}
page.addView(contentView);
如何将每个 imageView 设置为与 xml 中的父布局具有相同的宽度和高度?
【问题讨论】:
标签: java android-studio imageview horizontalscrollview