主布局 侧滑

public class MainActivity2 extends AppCompatActivity implements View.OnClickListener {

private AFragment aFragment;
private BFragment bFragment;
private TextView xlistViews;
private TextView tab_layout;
private DrawerLayout drawerLayout;
private FragmentManager manager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);

    initData();
    initView();
}

private void initData() {
    aFragment = new AFragment();
    bFragment = new BFragment();
}

private void initView() {
    xlistViews = findViewById(R.id.xListViews);
    xlistViews.setOnClickListener(this);
    tab_layout = findViewById(R.id.Tab_Layout);
    tab_layout.setOnClickListener(this);
    drawerLayout = findViewById(R.id.Drawer_layout);
    manager = getSupportFragmentManager();
}


@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.xListViews:
        manager.beginTransaction().replace(R.id.Framelayout,aFragment).commit();
        drawerLayout.closeDrawers();
        break;

        case R.id.Tab_Layout:
            manager.beginTransaction().replace(R.id.Framelayout,bFragment).commit();
            drawerLayout.closeDrawers();
            break;
    }
}

}

//MyApp
public class Mapp extends Application {

@Override
public void onCreate() {
    super.onCreate();

    ImageLoaderConfiguration imageLoaderConfiguration=ImageLoaderConfiguration.createDefault(this);
    ImageLoader.getInstance().init(imageLoaderConfiguration);
}

}

//*HttpUtils
public class HttpUtils {

public static String get(String urlStr) throws Exception {
    URL url=new URL(urlStr);
    HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    connection.setRequestMethod("GET");
    connection.setConnectTimeout(5000);
    InputStream stream = connection.getInputStream();
    String inputStr = getInputStr(stream);
    return inputStr;
}

private static String getInputStr(InputStream stream) throws IOException {
    BufferedReader reader=new BufferedReader(new InputStreamReader(stream));
    StringBuffer sb=new StringBuffer();
    String con=null;
    while ((con=reader.readLine())!=null){
        sb.append(con);
    }
    return sb.toString();
}

}
//*侧滑布局
<android.support.v4.widget.DrawerLayout xmlns:android=“http://schemas.android.com/apk/res/android
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:id="@+id/Drawer_layout">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/Framelayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        ></FrameLayout>
</RelativeLayout>
<LinearLayout
    android:layout_width="200dp"
    android:layout_height="match_parent"
    android:id="@+id/Zuo_Layout"
    android:layout_gravity="start"
    android:background="@color/colorhaokan"
    android:orientation="vertical">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:src="@mipmap/ic_launcher_round" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center"
        android:text="不吃肉" />

    <TextView
        android:id="@+id/xListViews"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="哈哈哈xListView" />

    <TextView
        android:id="@+id/Tab_Layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="呵呵呵TabLayout" />
</LinearLayout>

</android.support.v4.widget.DrawerLayout>

猜你喜欢

转载自blog.csdn.net/qq_43603312/article/details/83961497