[android开发之内容更新类APP]三、项目的基本功能之布局
来源:互联网 发布:北京网络职业技术学院 编辑:程序博客网 时间:2024/06/02 01:33
应用宝的下载地址:http://android.myapp.com/myapp/detail.htm?apkName=com.jov.laughter
其他的市场如木蚂蚁,安卓市场,搜狐也都有了
1.环境
建好你的android project
大家都知道,我这人不喜欢把一样事情做两遍,好吧,我开了个项目叫德国队吧(贴吧中,比较常去的两个吧)虽然是不同的名字,但是我会把它搞的跟搞笑吧一样(教程完了之后,再把这个坑填了),好,我的项目:
在开始之前呢,先给大家一个地址:
http://jgilfelt.github.io/android-actionbarstylegenerator/#name=example&compat=appcompat&theme=light&actionbarstyle=solid&texture=0&hairline=0&neutralPressed=0&backColor=fff%2C100&secondaryColor=fff%2C100&tabColor=f80%2C100&tertiaryColor=fff%2C100&accentColor=fff%2C100&cabBackColor=fff%2C100&cabHighlightColor=fff%2C100
对,里面是actionbar的设计,相关的内容咱也不多介绍了 ,选好你的样式,点击那个downloadzip按钮,把包下载下来,替换到项目中去。另外替换的时候,文件要记得修改,比如styles_example.xml(values和values-v14下的都要),还有mainfanst里面修改成你自己的样式,来看下效果:(图标什么的,贴吧里面copy的)
ok,先做点测试,打开我们的MainActivity
package com.jov.germany;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;import android.os.Bundle;import android.support.v7.app.ActionBarActivity;public class MainActivity extends ActionBarActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);testResource();}private void testResource(){new Thread(new Runnable(){@Overridepublic void run() {getContentFromNetwork();}}).start();}private boolean getContentFromNetwork() {String path = "http://tie163.qiniudn.com/record.txt";URL url;String str = "";try {url = new URL(path);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setReadTimeout(6 * 1000);if (conn.getResponseCode() == 200) { InputStream inStream = conn.getInputStream();str = readContent(inStream);System.out.println("test result="+str);}conn.disconnect();return true;} catch (MalformedURLException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return false;}private String readContent(InputStream inStream) {StringBuilder resultData = new StringBuilder("");try {InputStreamReader isr = new InputStreamReader(inStream);BufferedReader buffer = new BufferedReader(isr);String inputLine = null;while ((inputLine = buffer.readLine()) != null) {resultData.append(inputLine);}buffer.close();isr.close();} catch (IOException e) {e.printStackTrace();}return resultData.toString();}}
最后在mainfast.xml里加入下面的权限
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
测试一下,是否获取到了我们的网络资源:
你的是否成功了呢?
ok,我们继续
2,布局
咱们用tabhost作为主要的菜单,话不多说,看代码:
activity_main.xml
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_centerVertical="true" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" > </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" > <fragment android:id="@+id/image_tab" android:name="com.jov.germany.frame.ImageFrame" android:layout_width="match_parent" android:layout_height="match_parent" /> <fragment android:id="@+id/text_tab" android:name="com.jov.germany.frame.TextFrame" android:layout_width="match_parent" android:layout_height="match_parent" /> <fragment android:id="@+id/both_tab" android:name="com.jov.germany.frame.BothFrame" android:layout_width="match_parent" android:layout_height="match_parent" /> </FrameLayout> </LinearLayout></TabHost>
其中fragment的name里的类,等会会说,
ok,打开MainActivity
咱们重新修改一下:
package com.jov.germany;import android.os.Bundle;import android.support.v7.app.ActionBarActivity;import android.widget.TabHost;public class MainActivity extends ActionBarActivity {private TabHost tabHost;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initTab();}private void initTab() {tabHost = (TabHost) findViewById(android.R.id.tabhost);tabHost.setup();// tabHost.setBackgroundResource(R.drawable.topbar_bg);tabHost.addTab(tabHost.newTabSpec("imageTab").setIndicator("图片").setContent(R.id.image_tab));tabHost.addTab(tabHost.newTabSpec("textTab").setIndicator("日常").setContent(R.id.text_tab));tabHost.addTab(tabHost.newTabSpec("bothTab").setIndicator("合集").setContent(R.id.both_tab));tabHost.setCurrentTab(0);}}
下面来建我们的frame,新建ImageFrame.java、TextFrame.java、BothFrame.java里面的内容基本差不多,下面给一个例子:
ImageFrame.java
package com.jov.germany.frame;import android.annotation.SuppressLint;import android.app.Fragment;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import com.jov.germany.R;@SuppressLint("NewApi")public class ImageFrame extends Fragment{ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.image_frame, container, false); } }
ok我们还没有对应的layout,来一个image_frame.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > </RelativeLayout>
看下效果:
另外的两个是一样的哦,大家就自己建把,好把,先到这里,我们的框架已经有了,就等往里面塞东西了。
暂时先到这里。。。
代码点击这里
- [android开发之内容更新类APP]三、项目的基本功能之布局
- [android开发之内容更新类APP]四、项目的基本功能之布局(续)
- [android开发之内容更新类APP]一、开始前的整体说明
- [android开发之内容更新类APP]二、这几日的结果
- android app开发之app本地更新
- Android 开发之实时更新 App Widget
- Android 开发之实时更新 App Widget
- Android IOS 电视 开发之 app 更新
- Android 开发之实时更新 App Widget
- Android开发之App Widget(三)
- android优化(三)---App调试之UI布局篇
- android app之布局优化
- 【Android】Web开发之通知栏下载更新APP
- 【Android】Web开发之通知栏下载更新APP
- android 开发之布局
- android开发之布局
- android app开发之仿qq个人标签,自动换行的布局
- 献给初学iOS的小盆友们——微博app项目开发之三设置导航条
- 第四章 选择结构程序设计
- nginx安装
- SPOJ104 Highways,生成树计数
- HDU 5045 Contest (2014上海网络赛)
- C++不常用的mutable volatile __based explicit关键字
- [android开发之内容更新类APP]三、项目的基本功能之布局
- Java中关于递归算法
- C++中的cmath常用库函数
- SWAP函数的几种写法
- conn.setAutoCommit()用法及作用(转载)
- CodeForces 271A
- Mockups~!
- leetcode-Pow(x, n)
- Python宝典第三章:Python数据类型与基本语句