首页 > 代码库 > 安卓初体验
安卓初体验
好久没写博客了,最近一个月终于学习安卓了,实在是已经无力写博客了,印象中安卓应该是比JAVA高深100倍啊有莫有,结果却是比css还要啰嗦100倍啊,各种格式,各种上下左右,木完木了,看各种帮助文档看的想吐,学到现在已经无力吐槽了,只好又抽出为数不多的时间再去坚定自己的信心,好了废话不多说,最近在仿造今日头条客户端,接下来几个帖子写一下我从中学到的几个小小小知识:
1.下面完成的功能是
package com.jerehedu.todaynews;
import java.util.ArrayList;
import com.jerehedu.adapter.NewsPagerAdapter; import com.jerehedu.enteiy.ChannelItem; import com.jerehedu.fragment.NewsFragment;
import com.jerehedu.other.ViewDisplayTool;
import com.jerehedu.todaynews.R.color;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.HorizontalScrollView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.LayoutParams;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class MainActivity extends FragmentActivity {
//频道分类容器
private ViewPager viewPager;
private RadioGroup tabContainer;
private ArrayList<ChannelItem> defaultChannels;
private int channelItemWidth;
private HorizontalScrollView topCategoryScoll;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
initView(); setContent();
} public void setContent() {
initTabData();
initTab();
initViewPager();
}
private void initView() {
tabContainer = (RadioGroup) findViewById(R.id.tabColContainer);
channelItemWidth = ViewDisplayTool.getWindowWidth(this) / 7;
topCategoryScoll = (HorizontalScrollView) findViewById(R.id.topcategoryscroll);
viewPager = (ViewPager) findViewById(R.id.view_pager123); }
/** * 初始化频道数据 */
private void initTabData() {
defaultChannels = new ArrayList<ChannelItem>();
defaultChannels.add(new ChannelItem(1, "推荐", 1, 1, 1));
defaultChannels.add(new ChannelItem(2, "热点", 2, 1));
defaultChannels.add(new ChannelItem(3, "烟台", 3, 1));
defaultChannels.add(new ChannelItem(4, "时尚", 4, 1));
defaultChannels.add(new ChannelItem(5, "科技", 5, 1));
defaultChannels.add(new ChannelItem(6, "体育", 6, 1));
defaultChannels.add(new ChannelItem(7, "军事", 7, 1));
defaultChannels.add(new ChannelItem(8, "NBA", 8, 1));
defaultChannels.add(new ChannelItem(9, "CBA", 9, 1)); }
安卓初体验