0
Androidボトムシートが機能していません。 以下は私のコードですが、ボトムシートのデモを作成したいのですが、動作しておらず、ボトムシートが表示されていません。Android Buttomシートが機能しない
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>
は、実際に私は他のライブラリを使用してせずにabouveコードを使用してAndroid Support Library 23.2
を用いたボトムシートを実装したいが、それは動作しません。ありがとうございました。
はあなたがボトムシートのXMLを表示することができます追加しますか? – Apurva
https://github.com/Flipboard/bottomsheetで非常に素晴らしいボトムシートライブラリが見つかりました。そのタイプは多目的に非常に役立ちます –