android - 缩小屏幕上的对话框

标签 android android-layout android-dialogfragment

我希望我的对话框不像显示的图像那样适合整个屏幕。我应该怎么做才不会那么长(高度)。 enter image description here

public class SidemenuInfoDialogFragment extends DialogFragment {

      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.sidemenu_info_main, container, true);
        return layout;
      }

       @Override
       public Dialog onCreateDialog(Bundle savedInstanceState) {
         Dialog dialog = new Dialog(new ContextThemeWrapper(getActivity(), R.style.Theme_Window_NoMinWith));
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

            return dialog;
          }


}

View :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:id="@+id/sidemenu_info_main_relative">


            <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/text1"
                    android:text="TEST TEXT "/>


</RelativeLayout>

让我知道是否还需要其他东西来帮助我走上正确的道路来解决这个问题。

最佳答案

在对话框 View 中将 TextView 的高度和宽度作为“wrap_content”。喜欢:

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:id="@+id/sidemenu_info_main_relative">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/text1"
            android:text="TEST TEXT "/>

 </RelativeLayout>

关于android - 缩小屏幕上的对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31804559/

相关文章:

android - 文字转语音 : deprecated speak function in API Level 21

android - 操作栏/工具栏在以下 Lollipop 版本中不显示

android - 以编程方式更改线性布局上边距android

android - onStart() 是确定 "user has re-opened the app"的最佳位置是否正确?

android - 如何创建具有透明部分的 DialogFragment?

android - 使用SwipeRefreshLayout实现Pull to Refresh的一些问题

java - 带参数的 Dagger 构造函数注入(inject)

java - FlurryAgent.logEvent 和 FlurryAgent.onEvent 的区别

java - TabLayout 中的方法removeAllTabs() 不起作用

android - 第一个参数类型错误。需要 "android.app.fragment"