• Android杂谈--小知识点总结(1)


    此知识点总结是开发过程中遇到的比较棘手或者恶心的地方,所以随时更新,以备不时之需

    1. viewFlipper中的item如何动态设置高度?

    例如:

    <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等。

    原因:参见FrameLayout#onMeasure(int, int)的源码,android:measureAllChildren="true"时,将所有children加入到mMeasureAllChildren的链表中,然后再重新measure下。

    2. HorizontalScrollView显示不全或者layout_gravity失效的问题

    <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"这个属性即可。

     
  • 相关阅读:
    django监测登录成功事件
    大兔子生小兔子问题
    XML 命名空间(XML Namespaces)介绍以及节点读取方法
    喝汽水问题
    一个女程序员的男友需求说明书(转)
    ASP.NET学习(二)
    字典序排序
    如果说中国的程序员技术偏低,原因可能在这里(转)
    BI(摘)
    肝脏、心脏、脾脏、肺脏、肾脏的毒素表现以及食疗排毒
  • 原文地址:https://www.cnblogs.com/loulijun/p/3591992.html
Copyright © 2020-2023  润新知