我成功地在Fragment
中创建了一个ListView
。我也成功地加载了底部弹出窗口。
如果我点击列表中的第一项"One",则底部弹出窗口会出现。
如果我在底部弹出窗口外面单击,则底部弹出窗口会消失。
如果我再次点击列表中的第二项"Two",底部弹出窗口会再次出现。
如果我再次执行1),然后向下滑动底部弹出窗口并尝试执行3),屏幕仍然会变成灰色,就好像底部弹出窗口仍然显示但不可见...???
我该如何解决这个问题?
以下是我的代码。
SecondFragment.java:
/**
* A simple {@link Fragment} subclass.
*/
public class SecondFragment extends Fragment {
public SecondFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_second, container, false);
String[] faList = {
"One",
"Two",
};
ListView listView = (ListView) view.findViewById(R.id.listFa);
ArrayAdapter<String> listviewAdapter = new ArrayAdapter<String>(
getActivity(),
android.R.layout.simple_list_item_1,
faList
);
listView.setAdapter(listviewAdapter);
// Inflate the layout for this fragment
// return view;
final BottomSheetDialog bottomsheet = new BottomSheetDialog(this.getContext());
View bottomSheetView = inflater.inflate(R.layout.bottom_sheet, null);
bottomsheet.setContentView(bottomSheetView);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
bottomsheet.show();
}
});
return view;
}
}
fragment_second.xml
:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ifavaz.talker.SecondFragment">
<!-- TODO: Update blank fragment layout -->
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listFa" />
</FrameLayout>
bottom_sheet.xml
:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="30dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="30dp">
<FrameLayout
android:layout_width="280dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text is my text is my text text is my text is my text text is my text is my text text is my text is my text "
android:textSize="18sp"
android:textAlignment="textStart"
android:paddingRight="30dp" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="30dp">
<FrameLayout
android:layout_width="280dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text is my text is my text text is my text is my text text is my text is my text text is my text is my text "
android:textSize="18sp"
android:paddingRight="30dp" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="30dp">
<FrameLayout
android:layout_width="280dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text is my text is my text text is my text is my text text is my text is my text text is my text is my text "
android:textSize="18sp"
android:textAlignment="textStart"
android:paddingRight="30dp" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="30dp">
<FrameLayout
android:layout_width="280dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text is my text is my text text is my text is my text text is my text is my text text is my text is my text "
android:textSize="18sp"
android:textAlignment="textStart"
android:paddingRight="30dp" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>