问题描述 投票:0回答:1

我有什么:

enter image description here

我的代码是我的代码:

FragmentDiscover.kt enter image description hereval dialog = BottomSheetDialogFragmentNew.newInstance() dialog.show(parentFragmentManager, dialog.javaClass.simpleName)

bottomsheetdialogfragmentnew.kt

class BottomSheetDialogFragmentNew : BottomSheetDialogFragment() { private var binding: BottomSheetDialogAddNewBinding? = null companion object { fun newInstance(): BottomSheetDialogFragmentNew { val fragment = BottomSheetDialogFragmentNew() return fragment } } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { binding = BottomSheetDialogAddNewBinding.inflate(layoutInflater) return binding!!.root } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return super.onCreateDialog(savedInstanceState).apply { setCancelable(true) setCanceledOnTouchOutside(true) setOnKeyListener { _: DialogInterface, keyCode: Int, keyEvent: KeyEvent -> if (keyCode == KeyEvent.KEYCODE_BACK && keyEvent.action == KeyEvent.ACTION_UP) { dismiss() } return@setOnKeyListener false } } } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding!!.ivAnswerToSomeUsersRequestsInfo.setOnClickListener({ val bottomSheetDialogLayout = layoutInflater.inflate(R.layout.bottom_sheet_dialog_why_to_answer_users_questions, null) val dialog = BottomSheetDialog(requireContext()) dialog.setContentView(bottomSheetDialogLayout) dialog.setCanceledOnTouchOutside(true) bottomSheetDialogLayout.findViewById<Button>(R.id.b_ok).setOnClickListener { dialog.dismiss() } dialog.show() }) val bottomSheet: FrameLayout = dialog?.findViewById(com.google.android.material.R.id.design_bottom_sheet)!! bottomSheet.layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT val behavior = BottomSheetBehavior.from(bottomSheet) behavior.apply { peekHeight = resources.displayMetrics.heightPixels isHideable = true } } override fun onPause() { super.onPause() dismiss() } override fun onCancel(dialog: DialogInterface) { super.onCancel(dialog) dismiss() } }

bottom_sheet_dialog_add_new.xml

<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/tv_answer_to_request" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="20dp" android:layout_marginTop="20dp" android:text="Feeling strong today? 💪 " android:textColor="@color/black" android:textSize="20sp" android:textStyle="bold" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <Button android:id="@+id/b_answer_to_some_users_requests" style="@style/Widget.AppCompat.Button.Borderless" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="20dp" android:layout_marginTop="10dp" android:text="Answer to some users requests!" android:textAllCaps="false" android:textColor="?attr/colorPrimary" android:textSize="20sp" app:layout_constraintEnd_toStartOf="@id/guideline" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tv_answer_to_request" /> <TextView android:id="@+id/tv_or" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="or" android:textSize="16sp" android:layout_marginStart="20dp" app:layout_constraintBottom_toTopOf="@id/b_example" app:layout_constraintEnd_toStartOf="@id/guideline" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/b_answer_to_some_users_requests" /> <Button android:id="@+id/b_example" style="@style/Widget.AppCompat.Button.Borderless" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="20dp" android:text="This is an example text" android:textAllCaps="false" android:textColor="?attr/colorPrimary" android:textSize="20sp" app:layout_constraintEnd_toStartOf="@id/guideline" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tv_or" /> <androidx.constraintlayout.widget.Guideline android:id="@+id/guideline" android:layout_width="0dp" android:layout_height="wrap_content" android:orientation="vertical" app:layout_constraintGuide_percent="0.8" /> <ImageView android:id="@+id/iv_answer_to_some_users_requests_info" style="@style/Widget.AppCompat.Button.Borderless" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="20dp" android:layout_marginEnd="20dp" android:adjustViewBounds="true" android:background="@drawable/border_rounded_corners" android:contentDescription="Answer to users requests - info" android:foreground="?attr/selectableItemBackground" android:src="@drawable/question_mark" app:layout_constraintBottom_toBottomOf="@id/b_example" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/guideline" app:layout_constraintTop_toTopOf="@id/b_answer_to_some_users_requests" /> </androidx.constraintlayout.widget.ConstraintLayout>
如果您需要更多信息,请告诉我。
    

您在这里有多种可能性:

您可以使您的底部努力抽屉的高峰延伸更多。这意味着布局具有更高的空间。

您可以在文本视图布局xml中使用

android:singleLine="false"

android kotlin android-layout bottom-sheet android-bottomsheetdialog
1个回答
0
投票
,因此由于大小约束,文本不会被打破

    您可以尝试
  1. android:layout_height=""

    ,而不是在您的父限制布局上,而不是将其设置为固定值,以便LayoutInflater可以正确地完成其工作。

    您可以将不同的布局用作父母,即Framelayout或Relativelayout,这也可以改善这一点。
  2. 
    
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.