Android弹出框BottomSheet

烈酒焚心 提交于 2019-12-06 19:47:13
Android弹出框BottomSheet
    效果图如下:





















  首先:
 compile 'com.flipboard:bottomsheet-core:1.5.2'
    compile 'com.flipboard:bottomsheet-commons:1.5.2' // optional

布局如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.flipboard.bottomsheet.BottomSheetLayout
        android:id="@+id/bottomsheet"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="5">

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="1"
                android:textColor="#000000" />
        </LinearLayout>
    </com.flipboard.bottomsheet.BottomSheetLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">


        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:background="@color/colorPrimary"
            android:text="购物"
            android:textColor="#000000" />
    </LinearLayout>
</LinearLayout>


<com.flipboard.bottomsheet.BottomSheetLayout
</com.flipboard.bottomsheet.BottomSheetLayout>包含的布局是弹出框的弹出位置。


逻辑是:
package com.example.administrator.bottomsheetdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import com.flipboard.bottomsheet.BottomSheetLayout;

public class MainActivity extends AppCompatActivity {
    private ListView lv;
    private BottomSheetLayout bottomsheet;
    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.item_tan);
        bottomsheet = (BottomSheetLayout) findViewById(R.id.bottomsheet);

        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bottomsheet.showWithSheetView(LayoutInflater.from(MainActivity.this).inflate(R.layout.activity_main, bottomsheet, false));
                btn = (Button) findViewById(R.id.btn);
                lv = (ListView) findViewById(R.id.lv);
                btn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(MainActivity.this, "我被点击了", Toast.LENGTH_SHORT).show();

                    }
                });
                bottomsheet.dismissSheet();

            }
        });


    }
}

bottomsheet.dismissSheet();意思是再次点击的话关闭


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!