自定义对话框太小 [英] Custom dialog too small

查看:365
本文介绍了自定义对话框太小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有对话框。该应用程序运行正常,但该对话框是太小了,我想发挥更大dialog.How我能实现这个实现自定义的机器人活动? 这是我的布局XML

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@色/白
机器人:方向=垂直>

         <的LinearLayout
         机器人:layout_width =match_parent
         机器人:layout_height =WRAP_CONTENT
         机器人:方向=垂直
         机器人:背景=@可绘制/ view_more_borders>

         <的LinearLayout
             机器人:layout_width =match_parent
             机器人:layout_height =match_parent
             机器人:layout_weight =1
             机器人:方向=横向
             机器人:layout_marginTop =4DP
             机器人:重力=center_vertical>

             <的TextView
                 机器人:ID =@ + ID / share_amount
                 机器人:layout_width =0dp
                 机器人:layout_height =WRAP_CONTENT
                 机器人:layout_weight =1
                 机器人:文本=公司名称
                 机器人:textAppearance =机器人:ATTR / textAppearanceSmall
                 机器人:文字颜色=@色/ nice_blue
                 机器人:字体=SANS/>

            <的TextView
                机器人:ID =@ + ID / textViewCompanyName
                机器人:layout_width =0dp
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_weight =1.80
                机器人:文本=
                机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceSmall?

         < / LinearLayout中>


         <的LinearLayout
             机器人:layout_width =match_parent
             机器人:layout_height =match_parent
             机器人:layout_weight =1
             机器人:layout_marginTop =4DP
             机器人:重力=center_vertical>

             <的TextView
                机器人:ID =@ + ID / textView5
                机器人:layout_width =0dp
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_weight =1
                机器人:文本=每股价格

                机器人:textAppearance =机器人:ATTR / textAppearanceSmall
                机器人:文字颜色=@色/ nice_blue/>

            <的TextView
                机器人:ID =@ + ID / textViewprice_pershare
                机器人:layout_width =0dp
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_weight =2
                机器人:layout_alignBaseline =@ + ID /昨日
                机器人:layout_alignBottom =@ + ID /昨日
                机器人:layout_marginLeft =38dp
                机器人:fontFamily中=无衬线
                机器人:layout_toRightOf =@ + ID /公司
                机器人:文本=
                机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceSmall?
         < / LinearLayout中>

         <的LinearLayout
             机器人:layout_width =match_parent
             机器人:layout_height =match_parent
             机器人:layout_weight =1
             机器人:layout_marginTop =4DP
             机器人:重力=center_vertical>

              <的TextView
                    机器人:ID =@ + ID / textView4
                  机器人:layout_width =0dp
                  机器人:layout_height =WRAP_CONTENT
                  机器人:layout_weight =1
                  机器人:文本=总成本

                  机器人:textAppearance =机器人:ATTR / textAppearanceSmall
                  机器人:文字颜色=@色/ nice_blue/>

            <的TextView
                机器人:ID =@ + ID / textview_totalcost
                机器人:layout_width =0dp
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_weight =2
                机器人:layout_alignBaseline =@ + ID /昨日
                机器人:layout_alignBottom =@ + ID /昨日
                机器人:layout_marginLeft =38dp
                机器人:fontFamily中=无衬线
                机器人:layout_toRightOf =@ + ID /公司
                机器人:文本=
                机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceSmall?
         < / LinearLayout中>


         <的LinearLayout
             机器人:layout_width =match_parent
             机器人:layout_height =match_parent
             机器人:layout_weight =1
             机器人:layout_marginTop =4DP
             机器人:重力=center_vertical>

                 <的TextView
            机器人:ID =@ + ID / textView3
                     机器人:layout_width =0dp
                     机器人:layout_height =WRAP_CONTENT
                     机器人:layout_weight =1
                     机器人:文本=股份数目:

                     机器人:textAppearance =机器人:ATTR / textAppearanceSmall
                     机器人:文字颜色=@色/ nice_blue/>

            <的EditText
                机器人:ID =@ + ID / shareNumber
                机器人:layout_width =0dp
                机器人:layout_weight =2
                机器人:layout_height =WRAP_CONTENT
                机器人:inputType =数字
                机器人:fontFamily中=无衬线
                机器人:TEXTSIZE =12SP
                 >

            <不是requestFocus />
            < /的EditText>
         < / LinearLayout中>

         <的LinearLayout
             机器人:layout_width =match_parent
             机器人:layout_height =match_parent
             机器人:layout_weight =1
             机器人:layout_marginTop =4DP
             机器人:重力=center_vertical>


              <的TextView
        机器人:ID =@ + ID / textView2
                机器人:layout_width =0dp
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_weight =1
                机器人:文本=付款方式

                机器人:textAppearance =机器人:ATTR / textAppearanceSmall
                机器人:文字颜色=@色/ nice_blue/>

             <微调
                 机器人:ID =@ + ID / spinner_paymentmode
                 机器人:layout_width =0dp
                 机器人:layout_height =WRAP_CONTENT
                 机器人:layout_weight =2/>

         < / LinearLayout中>
     < / LinearLayout中>
     <按钮
    机器人:ID =@ + ID / button_buy_shares
    风格=@风格/ ButtonText
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:背景=@可绘制/ blue_button
    机器人:文本=买入/>
 

和这里是我的output.I想增加对话框的宽度和高度。

和我的Java文件

 公共类MyDialogFragment扩展DialogFragment {

公共MyDialogFragment(){

}

私人的EditText mEditText;

@覆盖
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,
        捆绑savedInstanceState){
    查看查看= inflater.inflate(R.layout.dialogfragment,集装箱);
    // mEditText =(EditText上)view.findViewById(R.id.txt_your_name);
    // getDialog()的setTitle(你好)。
    。getDialog()requestWindowFeature(Window.FEATURE_NO_TITLE);

    返回查看;
}
}
 

解决方案

更​​改对话框尺寸上运行时:

  yourDialog.show();
yourDialog.getWindow()的setLayout((6 *宽)/ 7,LayoutParams.WRAP_CONTENT)。
 

您可以做两个维度,在我的例子,我不仅改变了宽度。 希望它可以帮助!

修改

我忘了是在哪里我把宽度:

  DisplayMetrics指标= getResources()getDisplayMetrics()。
INT宽度= metrics.widthPixels;
INT高= metrics.heightPixels;
 

编辑2

试试这个code:

 对话yourDialog = dialogFragment.getDialog();
yourDialog.getWindow()的setLayout((6 *宽度)/ 7,(4 *高度)/ 5)。
 

I have an android activity that implements a custom dialog.The application is running ok but the dialog is too small,i want to display a bigger dialog.How can i achieve this? Here is my layout xml

<?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:background="@color/white"
android:orientation="vertical" >

         <LinearLayout 
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical"
         android:background="@drawable/view_more_borders">

         <LinearLayout 
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_weight="1"
             android:orientation="horizontal"
             android:layout_marginTop="4dp"
             android:gravity="center_vertical">

             <TextView
                 android:id="@+id/share_amount"
                 android:layout_width="0dp"
                 android:layout_height="wrap_content"
                 android:layout_weight="1"
                 android:text="Company Name:"
                 android:textAppearance="?android:attr/textAppearanceSmall"
                 android:textColor="@color/nice_blue"
                 android:typeface="sans" />

            <TextView
                android:id="@+id/textViewCompanyName"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1.80"
                android:text=" "
                android:textAppearance="?android:attr/textAppearanceSmall" />

         </LinearLayout>


         <LinearLayout 
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_weight="1"
             android:layout_marginTop="4dp"
             android:gravity="center_vertical">

             <TextView
                android:id="@+id/textView5"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Price per share:"

                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="@color/nice_blue" />

            <TextView
                android:id="@+id/textViewprice_pershare"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:layout_alignBaseline="@+id/Yesterday"
                android:layout_alignBottom="@+id/Yesterday"
                android:layout_marginLeft="38dp"
                android:fontFamily="sans-serif"
                android:layout_toRightOf="@+id/company"
                android:text=" "
                android:textAppearance="?android:attr/textAppearanceSmall" />
         </LinearLayout>

         <LinearLayout 
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_weight="1"
             android:layout_marginTop="4dp"
             android:gravity="center_vertical">

              <TextView
                    android:id="@+id/textView4"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_weight="1"
                  android:text="Total cost:"

                  android:textAppearance="?android:attr/textAppearanceSmall"
                  android:textColor="@color/nice_blue" />

            <TextView
                android:id="@+id/textview_totalcost"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:layout_alignBaseline="@+id/Yesterday"
                android:layout_alignBottom="@+id/Yesterday"
                android:layout_marginLeft="38dp"
                android:fontFamily="sans-serif"
                android:layout_toRightOf="@+id/company"
                android:text=" "
                android:textAppearance="?android:attr/textAppearanceSmall" />
         </LinearLayout>


         <LinearLayout 
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_weight="1"
             android:layout_marginTop="4dp"
             android:gravity="center_vertical">

                 <TextView
            android:id="@+id/textView3"
                     android:layout_width="0dp"
                     android:layout_height="wrap_content"
                     android:layout_weight="1"
                     android:text="Number of shares:"

                     android:textAppearance="?android:attr/textAppearanceSmall"
                     android:textColor="@color/nice_blue" />

            <EditText
                android:id="@+id/shareNumber"
                android:layout_width="0dp"
                android:layout_weight="2"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:fontFamily="sans-serif"
                android:textSize="12sp"
                 >

            <requestFocus />
            </EditText>
         </LinearLayout>

         <LinearLayout 
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_weight="1"
             android:layout_marginTop="4dp"
             android:gravity="center_vertical">


              <TextView
        android:id="@+id/textView2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Payment method:"

                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="@color/nice_blue" />

             <Spinner
                 android:id="@+id/spinner_paymentmode"
                 android:layout_width="0dp"
                 android:layout_height="wrap_content"
                 android:layout_weight="2" />

         </LinearLayout>   
     </LinearLayout>
     <Button
    android:id="@+id/button_buy_shares"
    style="@style/ButtonText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/blue_button"
    android:text="Buy" />

And here is my output.I want to increase the width and height of the dialog.

And my java file

public class MyDialogFragment extends DialogFragment {

public MyDialogFragment() {

}

private EditText mEditText;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.dialogfragment, container);
    // mEditText = (EditText) view.findViewById(R.id.txt_your_name);
    // getDialog().setTitle("Hello");
    getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);

    return view;
}
}

解决方案

Change your dialog dimension on runtime:

yourDialog.show();
yourDialog.getWindow().setLayout((6 * width)/7, LayoutParams.WRAP_CONTENT);

You can do that for both dimension, in my example i only changed the width. Hope it helps!

EDIT

I forgot to mention where i took width:

DisplayMetrics metrics = getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;

EDIT 2

Try this code:

Dialog yourDialog = dialogFragment.getDialog();
yourDialog.getWindow().setLayout((6 * width)/7, (4 * height)/5);

这篇关于自定义对话框太小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆