1
LinearLayoutの魔法使いにImageViewsを動的に追加するのはHorizontalScrollViewの内部です。親の親の次元に基づいて幅と高さを設定Android Studio
この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>
、これは私のコードです:私はparentlayoutと同じ幅と高さを持つように各ImageViewのを設定するにはどうすればよい
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);
XMLで?
imageView.getLayoutParams()を追加すると、width = ViewGroup.LayoutParams.MATCH_PARENT;画像は依然として画面幅のほぼ2倍です。 – Walter
ギャラリーアプリのようにイメージを次々にスクロールしますか? – Geryson
はい。しかし、いくつかのテキストビューの間に、 – Walter