Android雜談--小知識點總結(1)

此知識點總結是開發過程當中遇到的比較棘手或者噁心的地方,因此隨時更新,以備不時之需android

1. viewFlipper中的item如何動態設置高度?佈局

例如:post

<ViewFlipper
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">

<include layout="@layout/layoutone"/>

<include layout="@layout/layouttwo"/>

<include layout="@layout/layoutthree"/>

</ViewFlipper>

假如想作成一個layoutone是50dp,layouttwo是50dp,layoutthree是80dp高度的話,你會發如今子佈局中設置高度後,ViewFlipper切換時老是以子view中高度最大的值爲其高度值,也就是80dp。可是又不想讓layoutone和layouttwo過高,開始的時候想經過LayoutParams動態設置吧,惋惜不行(把viewflipper單獨出來才行),而後找到須要設置android:measureAllChildren="false",或者代碼調用setMeasureAllChildren(false);便可,由於默認狀況下measureAllChildren=true。設置後各個view的高度就不一樣了。該屬性也適合FrameLayout等。spa

緣由:參見FrameLayout#onMeasure(int, int)的源碼,android:measureAllChildren="true"時,將全部children加入到mMeasureAllChildren的鏈表中,而後再從新measure下。code

2. HorizontalScrollView顯示不全或者layout_gravity失效的問題blog

<HorizontalScrollView
            android:id="@+id/scrollView0"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:scrollbarAlwaysDrawHorizontalTrack="false"
            android:scrollbars="none" >

            <LinearLayout
                android:id="@+id/bookstore_category_filter0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:padding="8dip" >
            </LinearLayout>
        </HorizontalScrollView> 

如上代碼是能夠的,可是若是在LinearLayout中加入個android:layout_gravity="center_horizontal",就會出現顯示不全並且會在一側多出一塊的問題。貌似是這個屬性與HorizontalScrollView的屬性衝突。解決方法就是去掉layout_gravity="center_horizontal"這個屬性便可。three

相關文章
相關標籤/搜索