gpt4 book ai didi

android - DialogFragment 不会尊重 wrap_content

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:53:25 26 4
gpt4 key购买 nike

我有一个自定义的 DialogFragment 类,如下所示:

/**
* Dialog Fragment containing rating form.
*/
public class RatingDialogFragment extends DialogFragment {

public static final String TAG = "RatingDialog";

// ...


@Nullable
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dialog_rating, container, false);
ButterKnife.bind(this, v);

return v;
}

// ...
}

Root View 是一个LinearLayout

<?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="wrap_content"
android:orientation="vertical"
android:padding="16dp">

每个 subview 都有 android:layout_height="wrap_content"

但它看起来像这样。我可能做错了什么?

enter image description here

最佳答案

这在一定程度上是我的布局问题。在我的对话框底部有一个按钮栏:

<!-- Cancel and apply buttons -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />

<Button
android:id="@+id/button_cancel"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/cancel"
android:textColor="@color/greySecondary"
android:theme="@style/ThemeOverlay.FilterButton" />


<Button
android:id="@+id/button_search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/apply"
android:theme="@style/ThemeOverlay.FilterButton" />

</LinearLayout>

第一个 View(一个间隔)正在扩展以填充视口(viewport),将其更改为固定它:

    <View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />

我还必须将此添加到 DialogFragment 中的 onResume:

@Override
public void onResume() {
super.onResume();
getDialog().getWindow().setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}

关于android - DialogFragment 不会尊重 wrap_content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45851270/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com