android-仿QQ界面布局
2011-08-04 21:00
423 查看
仿QQ界面布局
老规矩。右键取得显示不出来的图片地址,利用下载工具下载这个图片。后缀改为rar即可得到源代码项目。
老规矩。右键取得显示不出来的图片地址,利用下载工具下载这个图片。后缀改为rar即可得到源代码项目。
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/root" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/default_bg" > <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="6.0" > <RelativeLayout android:id="@+id/layout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:layout_gravity="center_vertical" > <ImageView android:id="@+id/tab1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/tab1" android:layout_centerInParent="true" /> </RelativeLayout> <RelativeLayout android:id="@+id/layout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:layout_gravity="center_vertical" > <ImageView android:id="@+id/tab2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/tab2" android:layout_centerInParent="true" /> </RelativeLayout> <RelativeLayout android:id="@+id/layout3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:layout_gravity="center_vertical" > <ImageView android:id="@+id/tab3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/tab3" android:layout_centerInParent="true" /> </RelativeLayout> </LinearLayout> <RelativeLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0" android:background="#ffffff" android:gravity="center" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="android" android:textColor="#000fff" android:textSize="20dip" android:layout_centerInParent="true" android:layout_marginLeft="15dip" /> </RelativeLayout> </LinearLayout> </RelativeLayout>
package com.android521.activity; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.view.animation.TranslateAnimation; import android.widget.ImageView; import android.widget.RelativeLayout; public class MainActivity extends Activity { private RelativeLayout layout; private RelativeLayout layout1; private RelativeLayout layout2; private RelativeLayout layout3; private ImageView tab1; private ImageView tab2; private ImageView tab3; private ImageView first; private int current = 1; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initUI(); } private void initUI(){ layout = (RelativeLayout) findViewById(R.id.root); layout1 = (RelativeLayout) findViewById(R.id.layout1); layout2 = (RelativeLayout) findViewById(R.id.layout2); layout3 = (RelativeLayout) findViewById(R.id.layout3); tab1 = (ImageView) findViewById(R.id.tab1); tab1.setOnClickListener(onClickListener); tab2 = (ImageView) findViewById(R.id.tab2); tab2.setOnClickListener(onClickListener); tab3 = (ImageView) findViewById(R.id.tab3); tab3.setOnClickListener(onClickListener); RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); rl.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); first = new ImageView(this); first.setTag("first"); first.setImageResource(R.drawable.topbar_select); switch (current) { case 1: layout1.addView(first, rl); current = R.id.tab1; break; case 2: layout2.addView(first, rl); current = R.id.tab2; break; case 3: layout3.addView(first, rl); current = R.id.tab3; break; default: break; } } private boolean isAdd = false; private int select_width; private int select_height; private int firstLeft; private int startLeft; private void replace() { switch (current) { case R.id.tab1: changeTop(layout1); break; case R.id.tab2: changeTop(layout2); break; case R.id.tab3: changeTop(layout3); break; default: break; } } private void changeTop(RelativeLayout relativeLayout){ ImageView old = (ImageView) relativeLayout.findViewWithTag("first");; select_width = old.getWidth(); select_height = old.getHeight(); RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(select_width, select_height); rl.leftMargin = old.getLeft() + ((RelativeLayout)old.getParent()).getLeft(); rl.topMargin = old.getTop() + ((RelativeLayout)old.getParent()).getTop(); firstLeft = old.getLeft() + ((RelativeLayout)old.getParent()).getLeft(); ImageView iv = new ImageView(this); iv.setTag("move"); iv.setImageResource(R.drawable.topbar_select); layout.addView(iv , rl); relativeLayout.removeView(old); } private OnClickListener onClickListener = new OnClickListener(){ public void onClick(View v) { if(!isAdd){ replace(); isAdd = true; } ImageView top_select = (ImageView) layout.findViewWithTag("move"); int tabLeft; int endLeft = 0; boolean run = false; switch (v.getId()) { case R.id.tab1: if (current != R.id.tab1) { tabLeft = ((RelativeLayout) tab1.getParent()).getLeft() + tab1.getLeft() + tab1.getWidth() / 2; endLeft = tabLeft - select_width / 2; current = R.id.tab1; run = true; } break; case R.id.tab2: if (current != R.id.tab2) { tabLeft = ((RelativeLayout) tab2.getParent()).getLeft() + tab2.getLeft() + tab2.getWidth() / 2; endLeft = tabLeft - select_width / 2; current = R.id.tab2; run = true; } break; case R.id.tab3: if (current != R.id.tab3) { tabLeft = ((RelativeLayout) tab3.getParent()).getLeft() + tab3.getLeft() + tab3.getWidth() / 2; endLeft = tabLeft - select_width/2; current = R.id.tab3; run = true; } break; default: break; } if(run){ TranslateAnimation animation = new TranslateAnimation(startLeft, endLeft - firstLeft, 0, 0); startLeft = endLeft - firstLeft; animation.setDuration(400); animation.setFillAfter(true); top_select.bringToFront(); top_select.startAnimation(animation); } } }; }
相关文章推荐
- 【android】软键盘 - 仿 qq/微信 聊天界面布局
- android布局基础及范例(一):QQ登陆界面设计
- android布局基础及范例:QQ登陆界面设计
- [转]Android:布局实例之模仿QQ登录界面
- 使用层级观察器hierarchyviewer综合各种布局实现Android QQ2012登陆界面和注册界面
- Android UI布局—— 仿QQ登录界面
- 使用层级观察器HierarchyViewer综合各种布局实现Android QQ2012登陆界面和注册界面
- 使用层级观察器hierarchyviewer综合各种布局实现Android QQ2012登陆界面和注册界面
- Android:布局实例之模仿QQ登录界面
- android仿qq聊天界面的的布局适配器的写法
- Android,iOS打开手机QQ与指定用户聊天界面
- android 界面中的各种布局
- Android 仿QQ界面的实现
- Android自定义控件系列 六:利用添加自定义布局来搞定触摸事件的分发,解决组合界面中特定控件响应特定方向的事件
- Android常用布局之LinearLayout(线性布局)仿酷狗登录界面
- Android软件开发之盘点界面五大布局
- 从实践中学习Android——高仿QQ登录界面
- Android界面布局编程
- Android仿QQ微信开场导航以及登陆界面
- Android说明设置界面布局