1
LinearLayout 마녀에 ImageViews를 동적으로 추가하는 것은 HorizontalScrollView 내부에 있습니다.부모의 부모의 차원을 기반으로 너비와 높이를 설정하십시오. Android Studio
이제이 HorizontalScrollView의 부모 LinearLayout을 기반으로 ImageViews의 너비와 높이를 설정하고 싶습니다.
이
내 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와 같은 폭과 높이가 각각의 이미지 뷰를 설정하는 방법
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; 이미지는 여전히 화면 폭의 거의 두 배입니다. – Walter
갤러리 응용 프로그램에서와 같이 이미지를 차례로 스크롤 하시겠습니까? – Geryson
예. 하지만 두 텍스트 뷰 사이에 – Walter