您可以使用一個對話框片段。下面是小例子:
這是你的fragment_sample_dialog
<?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:gravity="center"
android:padding="10dp"
android:orientation="vertical">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/image" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lorem ipsum dolor sit amet..."
android:textSize="20dp" />
<Button
android:id="@+id/dismiss"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Dismiss" />
</LinearLayout>
這裏的佈局Dialogfragment的Java文件:
public class MyDialogFragment extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_sample_dialog, container, false);
getDialog().setTitle("Simple Dialog");
return rootView;
}
}
這裏是指示如何開始你的片段:
FragmentManager fm = getFragmentManager();
MyDialogFragment dialogFragment = new MyDialogFragment();
dialogFragment.show(fm, "Sample Fragment");