如图所示DialogFragment
除了按钮之外全是白色。我尝试了各种布局parrams和ConstraintLayout
设置,但白色背景感觉就像是一个z次序,
这就是ANdroid Studio布局编辑器的样子
我的xml:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:srcCompat="http://schemas.android.com/tools"
android:id="@+id/place_search_dialog"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:visibility="visible">
<ImageView
android:id="@+id/place_search_dialog_header_image_IV"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:contentDescription=""
android:scaleType="centerCrop"
app:layout_constraintBottom_toTopOf="@+id/guideline478"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
srcCompat:src="@drawable/place_picker_dialog_nobackground"/>
<Button
android:id="@+id/btn_place_dialog_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:padding="10dp"
android:text="@string/cancel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btn_place_dialog_ok"/>
<Button
android:id="@+id/btn_place_dialog_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:padding="10dp"
android:text="@string/ok"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btn_place_dialog_cancel"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"/>
<android.support.constraint.Guideline
android:id="@+id/guideline355"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.66"/>
<ImageView
android:id="@+id/imageView_street"
android:layout_width="74dp"
android:layout_height="48dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="@+id/btn_place_dialog_cancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.348"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/place_search_dialog_header_image_IV"
app:layout_constraintVertical_bias="0.581"
app:srcCompat="@drawable/avatar"/>
<android.support.constraint.Guideline
android:id="@+id/guideline478"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.28"/>
</android.support.constraint.ConstraintLayout>
更新
这是DialogFragment
public class GooglePlaceDetailsDialogFragment extends DialogFragment {
private View mRootView;
private BasePlace place;
private Unbinder unbinder;
RequestResponse requestResponse;
private PlaceDetails placeDetails;
public interface ShowPlaceListener {
void onShowPlace(BasePlace item);
}
private ShowPlaceListener mShowPlaceListener;
public static GooglePlaceDetailsDialogFragment newInstance(BasePlace item) {
GooglePlaceDetailsDialogFragment fragment = new GooglePlaceDetailsDialogFragment();
fragment.setPlace(item);
return fragment;
}
// Called to do initial creation of a fragment. This is called after onAttach and before onCreateView
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
mShowPlaceListener = (ShowPlaceListener) getTargetFragment();
} catch (ClassCastException e) {
throw new ClassCastException("Calling fragment must implement Callback ShowPlaceListener");
}
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
mRootView = inflater.inflate(R.layout.dialog_fragment_show_google_place_details, container);
ImageView imageViewStreet = mRootView.findViewById(R.id.imageView_street);
// Just unpack the details to make it smoother
this.requestResponse = place.requestResponse;
this.placeDetails = place.requestResponse.placeDetails;
unbinder = ButterKnife.bind(this, mRootView);
getDialog().setTitle("lkjkjlkj ");
if (placeDetails.url.equals("")) {
if (LogManager.isDebugable()) {
Picasso.with(getActivity()).setIndicatorsEnabled(true);
}
Picasso.with(getActivity())
.load(R.drawable.anon_user_48dp)
.transform(new CircleTransformation())
.into(imageViewStreet);
} else {
if (LogManager.isDebugable()) {
Picasso.with(getActivity()).setIndicatorsEnabled(true);
}
Picasso.with(getActivity())
.load(placeDetails.url)
.transform(new CircleTransformation())
.into(imageViewStreet);
}
return mRootView;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
}
@OnClick(R.id.btn_place_dialog_ok)
public void onSearchClicked() {
if (mShowPlaceListener != null) {
mShowPlaceListener.onShowPlace(place);
}
dismiss();
}
@OnClick(R.id.btn_place_dialog_cancel)
public void onCancelClicked() {
dismiss();
}
private void setPlace(BasePlace place) {
this.place = place;
}
@Override
public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
}
}
这是创作
GooglePlaceDetailsDialogFragment dialog = GooglePlaceDetailsDialogFragment.newInstance(item);
dialog.setTargetFragment(this, 0);
DialogUtils.showDialogFragment(getFragmentManager(), dialog);
的Util ..
public class DialogUtils {
private static String showDialogFragment(FragmentManager fragmentManager, DialogFragment dialogFragment,
String fragmentTag, boolean onlyIfNotDuplicate) {
// If only showing non duplicates dialogs, make sure the fragment isn't already in the manager
boolean doesFragmentExist = fragmentManager.findFragmentByTag(fragmentTag) != null;
if (!(onlyIfNotDuplicate && doesFragmentExist)) {
dialogFragment.show(fragmentManager, fragmentTag);
}
return fragmentTag;
}
public static String showDialogFragment(FragmentManager fragmentManager, DialogFragment dialogFragment,
boolean onlyIfNotDuplicate) {
return showDialogFragment(fragmentManager, dialogFragment, generateFragmentTag(dialogFragment), onlyIfNotDuplicate);
}
private static String showDialogFragment(FragmentManager fragmentManager, DialogFragment dialogFragment,
String fragmentTag) {
return showDialogFragment(fragmentManager, dialogFragment, fragmentTag, true);
}
public static String showDialogFragment(FragmentManager fragmentManager, DialogFragment dialogFragment) {
return showDialogFragment(fragmentManager, dialogFragment, generateFragmentTag(dialogFragment));
}
private static String generateFragmentTag(Fragment fragment) {
return fragment.getClass().getName();
}
}
答案 0 :(得分:1)
当我用app替换srcCompat:src=
时:srcCompat =`图片显示,奇怪AS没有抱怨这个错误