HorizontalScrollView를 사용하여 수평 ListView를 구현하고 코드 내에 '항목'을 추가하려고합니다. 항목을 추가하면 문제가 없습니다. 이제 각 항목을 ScrollView 너비의 1/7로 설정하여 스크롤하지 않고 정확히 7 개의 항목을 표시 할 수 있습니다. HorizontalScrollView 너비를 가져 오는 방법을 알아낼 수 없습니다.안드로이드 HorizontalScrollView 너비를 얻으려면
내 XML은 다음과 같습니다
<HorizontalScrollView
android:id="@+id/information_popup_dialog_listScrollView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="7" >
<LinearLayout
android:id="@+id/information_popup_dialog_listParent"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
이 같은 항목을 추가 : 내가있는 ScrollView의 폭을 얻기 위해 측정()를 사용하는 경우
LinearLayout listContainer = (LinearLayout) view
.findViewById(R.id.information_popup_dialog_listParent);
LinearLayout listItem = (LinearLayout) inflater.inflate(
R.layout.information_popup_dialog_list_item, listContainer,
false);
listItem.setLayoutParams(new LinearLayout.LayoutParams(
width, LayoutParams.MATCH_PARENT));
listContainer.addView(listItem);
내가 전체 너비를 얻을, 보이는 너비가 아닙니다. 따라서 내가 추가하는 모든 항목이 계속 증가합니다.
HorizontalScrollView scrollView = (HorizontalScrollView) view
.findViewById(R.id.information_popup_dialog_listScrollView);
scrollView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
System.out.println("Width: " + scrollView.getMeasuredWidth());
나는 모두 0 이렇게 어쨌든 거기에 복귀, .getLayoutParams(). 폭/getWidth()를 사용하여 여러 가지 방법을 시도? DialogFragment의 onCreateView() 메서드에서이 모든 작업을 수행하고 있습니다.
도움 주셔서 감사합니다.