2010-08-25 27 views
5

Tôi có một ScrolLView kết thúc tốt đẹp một ViewFlipper. Các nội dung trong ViewFlipper không có chiều cao bình đẳng, vì vậy màn hình thứ hai của tôi có một thanh cuộn rất lâu đến nỗi đi và về với nội dung trống:Tính toán lại ScrollView trên các chế độ xem ViewFlipper khác nhau?

<ScrollView android:id="@+id/outer_scroll" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:fillViewport="true"> 
<ViewFlipper android:id="@+id/flipper" 
android:layout_width="fill_parent" android:layout_height="fill_parent"> 

<EditText android:id="@+id/desc" style="@style/DescriptionArea" 
android:layout_width="fill_parent" android:layout_height="wrap_content" 
android:enabled="false" android:focusableInTouchMode="false" 
android:background="@null" /> 

<LinearLayout android:id="@+id/details_root" 
android:orientation="vertical" android:layout_width="fill_parent" 
android:layout_height="fill_parent" android:padding="10dp"> 

<TextView android:id="@+id/item_details" style="@style/DetailsLarge" 
android:textColor="#000" android:visibility="gone" 
android:layout_width="wrap_content" android:layout_height="fill_parent" 
android:text="@string/item_details_tags" /> 
<TextView android:id="@+id/tags" android:layout_width="wrap_content" 
android:layout_height="fill_parent" android:textColor="#000" 
android:visibility="gone" /> 
</LinearLayout> 
</ViewFlipper> 
</ScrollView> 

Vì vậy, ví dụ, khối EditText là rất dài, và thanh cuộn sẽ chụp tất cả. Tôi chạy đến LinearLayout và thanh cuộn tiếp tục qua nội dung TextView. Tôi về cơ bản cần nó để "tính toán lại" chiều cao xem.

Ngoài ra, việc gói EditText và LinearLayout trong ScrollViews của riêng nó không phải là một tùy chọn, vì sau đó bàn phím mềm/ảo chặn nội dung EditText.

+0

Ồ, tôi vừa hỏi một phút câu hỏi tương tự sau khi bạn ... http://stackoverflow.com/questions/3570362/getting-rid-of-extra-space-in-text-switcher – ekawas

Trả lời

16

Khi đo, ViewFlipper (cũng như ViewSwitcher, TextSwitcher, v.v. - tất cả con cháu của ViewAnimator) theo mặc định sẽ được định kích thước theo con lớn nhất, bao gồm cả con không nhìn thấy được.

Đặt cờ MeasureAllChildren false để thay đổi hành vi này chỉ sử dụng các con hiện đang nhìn thấy được khi đo kích thước:

ViewFlipper flipper = (ViewFlipper)findViewById(R.id.flipper); 
flipper.setMeasureAllChildren(false); 
+0

Cảm ơn! câu trả lời hay. –

5

Nếu bạn đang làm viewflipper của bạn trong xml bạn cũng có thể sử dụng android: measureAllChildren = "sai".

Các vấn đề liên quan