2

Android 底页不工作。下面是我的代码,我想创建底部表演示,但它不工作并且底部表没有显示。

    public class MainActivity extends AppCompatActivity  implements View.OnClickListener{
    private BottomSheetBehavior mBottomSheetBehavior;
    private Button button1;
    private View bottomSheet;

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

        getId();
        setListner();
        mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
    }

    private void getId() {
        try {
            button1 = (Button)findViewById(R.id.button1);
            bottomSheet = findViewById(R.id.bottom_sheet);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private void setListner() {
        try {
            button1.setOnClickListener(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Override
    public void onClick(View v)
    {
        try {
            switch (v.getId())
            {
                case R.id.button1:
                mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);

                    Log.e("Buttom clicked",">>");
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

这是我的 xml 文件。

        <android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingTop="24dp">

            <Button
                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button 1"
                android:padding="16dp"
                android:layout_margin="8dp"
                android:textColor="@android:color/white"
                android:background="@android:color/holo_green_dark"/>
        </LinearLayout>
    </ScrollView>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="350dp"
        android:clipToPadding="true"
        android:background="@android:color/holo_orange_light"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
        >
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/ic_launcher"
            android:padding="16dp"
            android:textSize="16sp"/>
    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

实际上,我想Android Support Library 23.2使用以上代码来实现底部工作表,而不使用任何其他库,但它不起作用。谢谢和提前。

4

1 回答 1

1

使用这个依赖编译 'com.cocosw:bottomsheet:1.2.0'

并添加此代码

new BottomSheet.Builder(getActivity(), R.style.BottomSheet_StyleDialog).
                    sheet(R.menu.bottom_sheet).title(displayname).listener(new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                        case R.id.btnOne:
                            // do something...
                            break;
                        case R.id.btnTwo:
                           // do something ...
                                  }
                             } 
            }).show();
于 2016-04-19T05:26:00.847 回答