2012年5月14日星期一

[zz]Windows下可用msysgit下载Android源码


Windows下可用msysgit下载Android源码。
比如,要下载base:

以上两句,分别下载了Android的4.0.4_r1.1和2.3.7_r1的base项目版本。
现在Google需要Username和Password,才能下载Android源码,需要先到https://android.googlesource.com/new-password
去生成。

Android中ListView的HeadView/FooterView

在Android中,可以对ListView设置HeaderView和FooterView,其中HeadView或者FooterView并不是ListItem的一部分。

我在使用listview.addFooterView()的时候,结果并没有显示出来FooterView。后来查文档看到,说是addFooterView()的调用一定要在listiew.setAdapter()之前,果然有效。

后来在这里看到,http://stackoverflow.com/questions/4317778/hide-footer-view-in-listview,其实,只要在addAdapter()之前,任意调用了addHeaderView或者addFooterView,在setAdapter()之后调用addHeaderView都是有效的。

参考地址:
http://developer.android.com/reference/android/widget/ListView.html

http://stackoverflow.com/questions/4317778/hide-footer-view-in-listview

https://code.google.com/p/android/issues/detail?id=12870

2012年5月11日星期五

Android在layout xml中使用include

在Android的layout样式定义中,可以使用xml文件方便的实现,有时候为了模块的复用,使用include标签可以达到此目的。
例如:  <include layout="@layout/otherlayout"></div>

Android开发的官方网站的说明在这里:https://developer.android.com/resources/articles/layout-tricks-reuse.html
其中,有提到: Similarly, you can override all the layout parameters. This means that any android:layout_* attribute can be used with the <include> tag,意思是任何android:layout_*属性都可以应用在<include>标签中。

如果使用如下代码:
<relativelayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        < textview
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/somestring"
            android:id="@+id/top" />
        
       
        <include < layout="@layout/otherlayout"
       android:layout_below="@id/top" />
        
</relativelayout >
发现include的otherlayout,并没有在如我们预期的在id/top这个TextView下面,而是忽略了android:layout_below属性。经过Google发现,很多人遇到类似的问题。

有解决方法是在include的外面再包一层LinearLayout,如下:
<linearlayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/top" >
        
        < include layout="@layout/otherlayout">
</linearlayout >
解答道:必须同时重载layout_width和layout_height熟悉,其他的layout_*属性才会起作用,否这都会被忽略掉。上面的例子应该写成这样:
<include layout="@layout/otherlayout">
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_below="@id/top" />


另外,关于xml的复用,还可以使用merge标签,merge标签主要是用来优化显示的,减少View树的层级,可以参考这里:https://developer.android.com/resources/articles/layout-tricks-merge.html, 翻译版在这里:http://apps.hi.baidu.com/share/detail/20871363

参考网址: