①布局
<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”
android:id="@+id/drawer"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal">
<RadioButton
android:id="@+id/radio0"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/select1"
android:button="@null" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/select2"
android:button="@null" />
<RadioButton
android:id="@+id/radio2"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/select3"
android:button="@null" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="350dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@drawable/vv"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="25dp"
android:layout_marginTop="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="45dp"
android:text="凉城已无爱i"
android:textColor="#fff"
android:textSize="25sp" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="60dp"
android:text="我的超级会员"
android:textColor="#fff"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="30dp"
android:text="QQ钱包"
android:textColor="#fff"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="30dp"
android:text="个性装扮"
android:textColor="#fff"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="30dp"
android:text="我的收藏"
android:textColor="#fff"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="30dp"
android:text="我的相册"
android:textColor="#fff"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="30dp"
android:text="我的文件"
android:textColor="#fff"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="30dp"
android:text="我的名片夹"
android:textColor="#fff"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="30dp"
android:text="免流量特权"
android:textColor="#fff"
android:textSize="20sp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
②帧布局
package mmy.example.com.yklx1;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.Toast;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import mmy.example.com.yklx1.base.BaseActivity;
import mmy.example.com.yklx1.fragment.Fragment1;
import mmy.example.com.yklx1.fragment.Fragment2;
import mmy.example.com.yklx1.fragment.Fragment3;
import mmy.example.com.yklx1.image.ImagePostos;
public class ShouActivity extends BaseActivity {
private FrameLayout frame;
private RadioGroup radioGroup;
private DrawerLayout drawer;
private FragmentManager sp;
private Fragment1 fragment1;
private Fragment2 fragment2;
private Fragment3 fragment3;
private ImageView imageView;
private String urlBitmap = "http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fimg5.duitang.com%2Fuploads%2Fitem%2F201410%2F05%2F20141005082835_2RTzn.thumb.700_0.jpeg&thumburl=http%3A%2F%2Fimg2.imgtn.bdimg.com%2Fit%2Fu%3D3846895839%2C2711067435%26fm%3D26%26gp%3D0.jpg";
@Override
protected void initView() {
//找到控件
frame = (FrameLayout) findViewById(R.id.frame);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
drawer = (DrawerLayout) findViewById(R.id.drawer);
imageView = (ImageView) findViewById(R.id.imageView);
//侧拉圆图
DisplayImageOptions displayImageOptions = ImagePostos.getDisplayImageOptions();
ImageLoader.getInstance().displayImage(urlBitmap,imageView,displayImageOptions);
sp = getSupportFragmentManager();
fragment1 = new Fragment1();
fragment2 = new Fragment2();
fragment3 = new Fragment3();
FragmentTransaction fragmentTransaction = sp.beginTransaction();
fragmentTransaction.add(R.id.frame,fragment1);
fragmentTransaction.add(R.id.frame,fragment2,"Fragment2");
fragmentTransaction.add(R.id.frame,fragment3);
fragmentTransaction.show(fragment1).hide(fragment2).hide(fragment3);
fragmentTransaction.commit();
radioGroup.check(radioGroup.getChildAt(0).getId());
}
@Override
protected void initData() {
//监听
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
FragmentTransaction fragmentTransaction1 = sp.beginTransaction();
switch (checkedId){
case R.id.radio0:
fragmentTransaction1.show(fragment1).hide(fragment2).hide(fragment3);
break;
case R.id.radio1:
fragmentTransaction1.show(fragment2).hide(fragment1).hide(fragment3);
break;
case R.id.radio2:
fragmentTransaction1.show(fragment3).hide(fragment1).hide(fragment2);
break;
}
fragmentTransaction1.commit();
}
});
//侧拉监听
drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(@NonNull View view, float v) {
}
@Override
public void onDrawerOpened(@NonNull View view) {
Toast.makeText(ShouActivity.this,"欢迎您!",Toast.LENGTH_SHORT).show();
}
@Override
public void onDrawerClosed(@NonNull View view) {
Toast.makeText(ShouActivity.this,"您慢走!",Toast.LENGTH_SHORT).show();
}
@Override
public void onDrawerStateChanged(int i) {
}
});
}
@Override
protected int getLayoutId() {
return R.layout.activity_shou;
}
//频道管理传值
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Fragment fragment2 = getSupportFragmentManager().findFragmentByTag("Fragment2");
fragment2.onActivityResult(requestCode,resultCode,data);
}
}