L遷客

          技術博客
          隨筆 - 1, 文章 - 12, 評論 - 1, 引用 - 0

          導航

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          搜索

          •  

          最新評論

          Android 高仿QQ 界面滑動效果

          Android 高仿QQ 界面滑動效果

          點擊或者滑動切換畫面,用ViewPager實現,

           

           

          首先是布局文件:

          <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"

              android:layout_width="match_parent"

              android:layout_height="match_parent"

              android:orientation="vertical" >

              <LinearLayout

                  android:layout_width="match_parent"

                  android:layout_height="62dip"

                  android:orientation="vertical"  

                  android:background="@drawable/top_theme_blue">

                  <LinearLayout

                      android:layout_width="match_parent"

                      android:layout_height="36dip"

                      android:orientation="horizontal"  

                      android:gravity="center_vertical">

                      <ImageView

                          android:id="@+id/main_avatar"

                          android:layout_width="32dip"

                          android:layout_height="32dip"

                          android:src="@drawable/avatar" />

                      <TextView  

                          android:id="@+id/main_nick"

                          android:layout_width="wrap_content"

                          android:layout_height="wrap_content"

                          android:textColor="#FFFFFF"

                          android:text="Vestigge"/>

                      <ImageView  

                          android:layout_width="14dip"

                          android:layout_height="14dip"

                          android:src="@drawable/status_online"/>

                  </LinearLayout>

                  <LinearLayout

                      android:layout_width="match_parent"

                      android:layout_height="26dip"

                      android:orientation="horizontal"  

                      android:gravity="bottom">

                      <RadioGroup    

                          android:id="@+id/main_radiogroup"

                          android:orientation="horizontal"

                          android:paddingTop="1dp"  

                          android:layout_width="fill_parent"    

                          android:layout_height="wrap_content">  

                          <RadioButton    

                              android:id="@+id/main_radio_recent"    

                              android:checked="true"    

                              android:text="動態"  

                              android:textColor="@color/tab_text"

                              android:drawableBottom="@drawable/top_tab_selector"

                              style="@style/radio_style"/>      

                          <RadioButton    

                              android:id="@+id/main_radio_buddy"  

                              android:text="群組"

                              android:textColor="@color/tab_text"  

                              android:drawableBottom="@drawable/top_tab_selector"

                              style="@style/radio_style"/>  

                          <RadioButton    

                              android:id="@+id/main_radio_group"    

                              android:text="好友"  

                              android:textColor="@color/tab_text"

                              android:drawableBottom="@drawable/top_tab_selector"

                              style="@style/radio_style"

                              android:checked="true"/>

                          <RadioButton    

                              android:id="@+id/main_radio_trends"    

                              android:text="會話"  

                              android:textColor="@color/tab_text"

                              android:drawableBottom="@drawable/top_tab_selector"

                              style="@style/radio_style"/>

                      </RadioGroup>    

                  </LinearLayout>

              </LinearLayout>

              <android.support.v4.view.ViewPager

                  android:id="@+id/main_viewpager"

                  android:layout_width="match_parent"

                  android:layout_height="match_parent" >

              </android.support.v4.view.ViewPager>    

          </LinearLayout>

          代碼:

           

          public class MainActivity extends ActivityGroup {

              private static final String TRENDS="動態";

              private static final String GROUP="群組";

              private static final String BUDDY="好友";

              private static final String RECENT="會話";

              private ArrayList<View> pageViews;

              private RadioGroup radioGroup;

              private ViewPager viewPager;

           

              public void onCreate(Bundle savedInstanceState) {

                  super.onCreate(savedInstanceState);

                  requestWindowFeature(Window.FEATURE_NO_TITLE);

                  setContentView(R.layout.activity_main);

                  

                  initView();

                  viewPager=(ViewPager) findViewById(R.id.main_viewpager);

                  viewPager.setAdapter(new PagerAdapter(){

                      public int getCount() {

                          return pageViews.size();

                      }

                      public boolean isViewFromObject(View view, Object objcet) {

                          return view==objcet;

                      }

                      //這里會對需要進行水平切換的頁面進行了加載和初始化 android:tileMode="repeat" 

                      public Object instantiateItem(View view, int id) {

                          ((ViewPager)view).addView(pageViews.get(id));

                          return pageViews.get(id);

                      }

                      public void destroyItem(View view, int id, Object arg2) {  

                          ((ViewPager) view).removeView(pageViews.get(id));  

                      }

                  });

                  viewPager.setCurrentItem(2);//默認顯示的是好友頁面 

                  radioGroup = (RadioGroup) findViewById(R.id.main_radiogroup);

                  radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                      public void onCheckedChanged(RadioGroup group, int checkedId) {

                          setClick(checkedId);

                      }

                  });

              }

              

              void initView() {

                  pageViews=new ArrayList<View>();

                  View view1 = getLocalActivityManager().startActivity(TRENDS,

                          new Intent(this, TrendsActivity.class)).getDecorView();

                  View view2 = getLocalActivityManager().startActivity(GROUP,

                          new Intent(this, GroupActivity.class)).getDecorView();

                  View view3 = getLocalActivityManager().startActivity(BUDDY,

                          new Intent(this, BuddyActivity.class)).getDecorView();

                  View view4 = getLocalActivityManager().startActivity(RECENT,

                          new Intent(this, RecentActivity.class)).getDecorView();

                  pageViews.add(0,view1);

                  pageViews.add(1,view2);

                  pageViews.add(2,view3);

                  pageViews.add(3,view4);

              }

           

              public void setClick(int id) {

                  switch(id){

                  case R.id.main_radio_trends:

                      viewPager.setCurrentItem(0);

                      break;

                  case R.id.main_radio_group:

                      viewPager.setCurrentItem(1);

                      break;

                  case R.id.main_radio_buddy:

                      viewPager.setCurrentItem(2);

                      break;

                  case R.id.main_radio_recent:

                      viewPager.setCurrentItem(3);

                      break;

                  }

              }

              @Override

              public boolean onCreateOptionsMenu(Menu menu) {

                  getMenuInflater().inflate(R.menu.activity_main, menu);

                  return true;

              }

          }

          posted on 2013-02-24 16:46 L遷客 閱讀(210) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 出国| 京山县| 息烽县| 日照市| 怀安县| 三都| 淳化县| 紫阳县| 玛曲县| 东乌珠穆沁旗| 龙口市| 常宁市| 桂阳县| 安岳县| 富民县| 凭祥市| 景宁| 昌江| 饶平县| 增城市| 资溪县| 辛集市| 陇南市| 大连市| 红原县| 京山县| 镇沅| 湖南省| 桦南县| 那曲县| 松江区| 洛南县| 永清县| 汨罗市| 兴海县| 赣榆县| 汕头市| 岚皋县| 邯郸市| 吉首市| 林州市|