仿微信界面的只能点击,不能滑动,和随机显示不同的布局

来源:互联网 发布:网络犯罪管辖权 编辑:程序博客网 时间:2024/05/14 18:07

1.xml文件

activity.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" >    <FrameLayout        android:id="@+id/id_fragment"        android:name="com.hanju.smartrouter.fragment.HJUserfragment"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:layout_above="@+id/linearLayout1"        android:layout_below="@+id/textView1" >    </FrameLayout>    <TextView        android:id="@+id/textView1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_alignParentTop="true"        android:drawableRight="@drawable/nowifi"        android:gravity="center"        android:text="免费在线" />    <LinearLayout        android:id="@+id/linearLayout1"        android:layout_width="fill_parent"        android:layout_height="55dp"        android:layout_alignParentBottom="true">        <LinearLayout            android:id="@+id/link"            android:layout_width="0dp"            android:layout_height="fill_parent"            android:layout_weight="1"            android:descendantFocusability="beforeDescendants"            android:gravity="center"            android:orientation="vertical" >            <ImageButton                android:id="@+id/btn_tab_bottom_link"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="#0000"                android:clickable="false"                android:src="@drawable/no_link" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="连接" />        </LinearLayout>        <LinearLayout            android:id="@+id/server"            android:layout_width="0dp"            android:layout_height="fill_parent"            android:layout_weight="1"            android:descendantFocusability="beforeDescendants"            android:gravity="center"            android:orientation="vertical" >            <ImageButton                android:id="@+id/btn_tab_bottom_server"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="#0000"                android:clickable="false"                android:src="@drawable/no_server" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="服务" />        </LinearLayout>        <LinearLayout            android:id="@+id/user"            android:layout_width="0dp"            android:layout_height="fill_parent"            android:layout_weight="1"            android:descendantFocusability="beforeDescendants"            android:gravity="center"            android:orientation="vertical" >            <ImageButton                android:id="@+id/btn_tab_bottom_user"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="#0000"                android:clickable="false"                android:src="@drawable/no_user" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="我的" />        </LinearLayout>    </LinearLayout>    <View        android:layout_width="match_parent"        android:layout_height="1dp"        android:layout_alignBottom="@+id/id_fragment_link"        android:layout_alignParentLeft="true"        android:background="#000000" /></RelativeLayout>

fragment01.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:id="@+id/rly_guang"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_alignParentLeft="true"        android:layout_alignParentTop="true"        android:background="@drawable/guang01"       android:visibility="gone" >    </RelativeLayout>     <ImageButton            android:id="@+id/imageButton1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_alignParentBottom="true"            android:layout_centerHorizontal="true"            android:layout_marginBottom="60dp"            android:src="@drawable/button_guang" />        <TextView            android:id="@+id/textView1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_alignTop="@+id/imageButton1"            android:layout_centerHorizontal="true"            android:layout_marginTop="45dp"            android:text="点击连接wifi" />        <ListView            android:id="@+id/lt_content"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:layout_alignParentTop="true"            android:visibility="gone" >        </ListView></RelativeLayout>

MainActivity.java文件中


package com.hanju.smartrouter.ui;import android.app.Activity;import android.app.FragmentManager;import android.app.FragmentTransaction;import android.os.Bundle;import android.text.Layout;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageButton;import android.widget.LinearLayout;import android.widget.RadioButton;import com.hanju.smarterroutter.R;import com.hanju.smartrouter.fragment.HJLinkfragment;import com.hanju.smartrouter.fragment.HJServerfragment;import com.hanju.smartrouter.fragment.HJUserfragment;public class MainActivity extends Activity implements OnClickListener{private HJLinkfragment mLink = null;private HJServerfragment mServer = null;private HJUserfragment mUser = null;private LinearLayout mRbLink = null;private LinearLayout mRbServer = null;private LinearLayout mRbUser = null;private ImageButton mImgLink;private ImageButton mImgServer;private ImageButton mImgUser;//用来管理fragmentprivate FragmentManager mFragmentManager = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mFragmentManager = getFragmentManager();__init();__setButtonSelection(0);}private void __init() {mRbLink=(LinearLayout) findViewById(R.id.link);mRbServer=(LinearLayout) findViewById(R.id.server);mRbUser=(LinearLayout) findViewById(R.id.user);mImgLink=(ImageButton) findViewById(R.id.btn_tab_bottom_link);mImgServer=(ImageButton) findViewById(R.id.btn_tab_bottom_server);mImgUser=(ImageButton) findViewById(R.id.btn_tab_bottom_user);mRbLink.setOnClickListener(this);mRbServer.setOnClickListener(this);mRbUser.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.link:__setButtonSelection(0);break;case R.id.server:__setButtonSelection(1);break;case R.id.user:__setButtonSelection(2);break;default:break;}}//设置底部按钮的选择private void __setButtonSelection(int index) {//重置按钮__resetBtn();FragmentTransaction transaction = mFragmentManager.beginTransaction();__hideFragments(transaction);switch (index) {case 0:mImgLink.setImageResource(R.drawable.link);if (mLink == null) {mLink = new HJLinkfragment();transaction.add(R.id.id_fragment, mLink);}else {transaction.show(mLink);}break;case 1:mImgServer.setImageResource(R.drawable.server);if (mServer == null) {mServer = new HJServerfragment();transaction.add(R.id.id_fragment, mServer);}else {transaction.show(mServer);}break;case 2://当点击了button是改变图片mImgUser.setImageResource(R.drawable.user);if (mUser == null) {mUser = new HJUserfragment();transaction.add(R.id.id_fragment, mUser);}else {transaction.show(mUser);}break;}//提交,***最重要的一步别忘了transaction.commit();}//重置底部buttonprivate void __resetBtn(){mImgLink.setImageResource(R.drawable.no_link);mImgServer.setImageResource(R.drawable.no_server);mImgUser.setImageResource(R.drawable.no_user);}private void __hideFragments(FragmentTransaction transaction) {if (mLink !=null) {transaction.hide(mLink);  }if (mServer !=null) {transaction.hide(mServer);  }if (mUser !=null) {transaction.hide(mUser);  }}}


MainActivity.java文件



package com.hanju.smartrouter.ui;import android.app.Activity;import android.app.FragmentManager;import android.app.FragmentTransaction;import android.os.Bundle;import android.text.Layout;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageButton;import android.widget.LinearLayout;import android.widget.RadioButton;import com.hanju.smarterroutter.R;import com.hanju.smartrouter.fragment.HJLinkfragment;import com.hanju.smartrouter.fragment.HJServerfragment;import com.hanju.smartrouter.fragment.HJUserfragment;public class MainActivity extends Activity implements OnClickListener{private HJLinkfragment mLink = null;private HJServerfragment mServer = null;private HJUserfragment mUser = null;private LinearLayout mRbLink = null;private LinearLayout mRbServer = null;private LinearLayout mRbUser = null;private ImageButton mImgLink;private ImageButton mImgServer;private ImageButton mImgUser;//用来管理fragmentprivate FragmentManager mFragmentManager = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mFragmentManager = getFragmentManager();__init();__setButtonSelection(0);}private void __init() {mRbLink=(LinearLayout) findViewById(R.id.link);mRbServer=(LinearLayout) findViewById(R.id.server);mRbUser=(LinearLayout) findViewById(R.id.user);mImgLink=(ImageButton) findViewById(R.id.btn_tab_bottom_link);mImgServer=(ImageButton) findViewById(R.id.btn_tab_bottom_server);mImgUser=(ImageButton) findViewById(R.id.btn_tab_bottom_user);mRbLink.setOnClickListener(this);mRbServer.setOnClickListener(this);mRbUser.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.link:__setButtonSelection(0);break;case R.id.server:__setButtonSelection(1);break;case R.id.user:__setButtonSelection(2);break;default:break;}}//设置底部按钮的选择private void __setButtonSelection(int index) {//重置按钮__resetBtn();FragmentTransaction transaction = mFragmentManager.beginTransaction();__hideFragments(transaction);switch (index) {case 0:mImgLink.setImageResource(R.drawable.link);if (mLink == null) {mLink = new HJLinkfragment();transaction.add(R.id.id_fragment, mLink);}else {transaction.show(mLink);}break;case 1:mImgServer.setImageResource(R.drawable.server);if (mServer == null) {mServer = new HJServerfragment();transaction.add(R.id.id_fragment, mServer);}else {transaction.show(mServer);}break;case 2://当点击了button是改变图片mImgUser.setImageResource(R.drawable.user);if (mUser == null) {mUser = new HJUserfragment();transaction.add(R.id.id_fragment, mUser);}else {transaction.show(mUser);}break;}//提交,***最重要的一步别忘了transaction.commit();}//重置底部buttonprivate void __resetBtn(){mImgLink.setImageResource(R.drawable.no_link);mImgServer.setImageResource(R.drawable.no_server);mImgUser.setImageResource(R.drawable.no_user);}private void __hideFragments(FragmentTransaction transaction) {if (mLink !=null) {transaction.hide(mLink);  }if (mServer !=null) {transaction.hide(mServer);  }if (mUser !=null) {transaction.hide(mUser);  }}}


0 0
原创粉丝点击