3.3

协调者布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
    tools:context=".Main2Activity">

    <!--  通过协调者布局,取到滑动事件
     它可以让你定制当某个可滚动View的滚动手势发生变化时,
     其内部的子View实现何种动作。  -->
    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:id="@+id/app_bar"
        android:layout_height="wrap_content">

        <!--        可折叠布局 可以单做帧布局来使用
            scroll|exitUntilCollapsed 与minHeight 结合使用 效果最常用
            app:contentScrim="@color/colorAccent" 蒙版效果-->
        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:minHeight="50dp"
            app:collapsedTitleGravity="left"
            app:expandedTitleGravity="bottom|right"
            app:contentScrim="@color/colorAccent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            >

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:src="@mipmap/ic_launcher"
                android:scaleType="centerCrop" />

            <!--            折叠以后留下的bar
            layout_collapseMode 吸附效果-->
            <androidx.appcompat.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="50dp"
                app:title="标题"
                android:id="@+id/bar"
                app:layout_collapseMode="pin" />
        </com.google.android.material.appbar.CollapsingToolbarLayout>

    </com.google.android.material.appbar.AppBarLayout>

    <!--  ScrollView的替代品
     layout_behavior属性为固定写法-> 点进去看看 -->
    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="500dp"
                android:background="#ff0000" />

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:src="@drawable/ic_launcher_background" />


        </LinearLayout>
    </androidx.core.widget.NestedScrollView>


    <!--    圆形风格按钮-->
    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|right"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="10dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

侧拉抽屉

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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"
    tools:context=".Main3Activity">
    <LinearLayout
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:orientation="horizontal"
        android:background="#E41BE4"
        android:layout_height="match_parent">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="这么样:"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="250dp"
        android:background="#0581EE"
        android:orientation="horizontal"
        android:id="@+id/left_layout"
        android:layout_gravity="start"
        android:layout_height="match_parent">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="阿迪达斯更多干啥"/>
    </LinearLayout>



</androidx.drawerlayout.widget.DrawerLayout>

头部TabLayout布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context=".Main4Activity">
    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tab"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></com.google.android.material.tabs.TabLayout>

</LinearLayout>

头部TabLayout代码

package com.example.day12;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.tabs.TabLayout;

public class Main4Activity extends AppCompatActivity {

    private TabLayout tab;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);
        initView();
        tab.addTab(tab.newTab().setText("这是什么玩意").setIcon(R.mipmap.ic_launcher));
        tab.addTab(tab.newTab().setText("这是什么玩意").setIcon(R.mipmap.ic_launcher));
        tab.addTab(tab.newTab().setText("这是什么玩意").setIcon(R.mipmap.ic_launcher));
        tab.addTab(tab.newTab().setText("这是什么玩意").setIcon(R.mipmap.ic_launcher));
        tab.addTab(tab.newTab().setText("这是什么玩意").setIcon(R.mipmap.ic_launcher));
    }

    private void initView() {
        tab = (TabLayout) findViewById(R.id.tab);
    }
}

单例(饿汉式)

package com.example.day12;

//饿汉式 饥汗试
public class HttpUtil {

    private static HttpUtil httpUtil = new HttpUtil();

    public static HttpUtil getinstance(){
        return httpUtil;
    }

    private HttpUtil(){

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值