Android弹出框BottomSheet

来源:互联网 发布:数据库触发器工作原理 编辑:程序博客网 时间:2024/06/05 00:18
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();意思是再次点击的话关闭


0 0
原创粉丝点击