Android知识点小结

来源:互联网 发布:java 微信支付api 编辑:程序博客网 时间:2024/05/29 17:44

Android中有很多零散的知识点,打算将平时开发中所遇到的一些记录下来,既可以加强记忆,也方便其他人查阅,共同进步。这篇博客会定期不断更新。

1.获得布局加载器LayoutInflater的三种方法:
// 方法之一:
LayoutInflater inflater = getLayoutInflater(); //调用Activity的getLayoutInflater()方法
// 方法之二:
LayoutInflater inflater = LayoutInflater.from(Context context);
// 方法之三:
LayoutInflater inflater =
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
感兴趣的可以查看源码,我们会发现最终调用的都是context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)。

2.Arrays.asList() 把数组转换成一个集合 注意:这个集合不支持删除、和添加,因为它是一个不可变的集合。

3.全屏显示
(1).android:theme=”@android:style/Theme.Holo.Light.NoActionBar.Fullscreen”
(2).android:theme=”@android:style/Theme.NoTitleBar.Fullscreen”

4.ProgressBar设置为横向,需要设置属性:
style=”@android:style/Widget.ProgressBar.Horizontal”

5.很多网络数据加载框架,实际上都是对HttpURLConnection与HttpClient进行封装,基本原理要搞清楚

public static String getDataFromNet(){        String path="";        String result="";        try {            URL url = new URL(path);            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();            urlConnection.setRequestMethod("GET");            urlConnection.setDoInput(true);            urlConnection.connect();            if(urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK){            result = (String) urlConnection.getContent();        } catch (Exception e) {            e.printStackTrace();        }        return result;    }
public static String getDataFromNet(String url) {        String reuslt = null;        HttpClient client = new DefaultHttpClient();        HttpGet get = new HttpGet(url);        try {            HttpResponse response = client.execute(get);            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {            HttpEntity entity = response.getEntity();            reuslt = EntityUtils.toString(entity);        } catch (IOException e) {            e.printStackTrace();        }        return reuslt;    }

6.ListView隐藏分割线的三种方法:
1).设置android:divider=”@null”
2).设置android:divider=”#00000000”
3).设置分割线的高度为0,setDividerHeight(0)

原创粉丝点击