标签:back tor oid iss near any raw net csdn
大家都知道,我这人不喜欢把一样事情做两遍,好吧,我开了个项目叫德国队吧(贴吧中。比較常去的两个吧)尽管是不同的名字,可是我会把它搞的跟搞笑吧一样(教程完了之后,再把这个坑填了)。好。我的项目:
在開始之前呢,先给大家一个地址:
对,里面是actionbar的设计,相关的内容咱也不多介绍了 ,选好你的样式。点击那个downloadzipbutton,把包下载下来,替换到项目中去。另外替换的时候。文件要记得改动。比方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 { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); testResource(); } private void testResource(){ new Thread(new Runnable(){ @Override public 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; @Override protected 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); } }
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); } }
<?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]三、项目的基本功能之布局
标签:back tor oid iss near any raw net csdn
原文地址:http://www.cnblogs.com/claireyuancy/p/6718681.html