Alertdialog inflatter未显示所有值

时间:2016-12-30 06:53:47

标签: android android-alertdialog layout-inflater

使用layout-inflatter显示自定义alertdialog。但是当Textview里面的alertdialoge包含一个很大的值,它没有显示.. enter image description here

当它包含一个小值时,它确定.. enter image description here

我的java代码......

 AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(Consultation.this);

            LayoutInflater inflater = getLayoutInflater();
            View dialogView = inflater.inflate(R.layout.alert_label_editor, null);
            dialogBuilder.setView(dialogView);

            TextView con=(TextView)dialogView.findViewById(R.id.textView29);
            con.setText("Consultation on "+item.getString(4));
            TextView des=(TextView)dialogView.findViewById(R.id.textView28);
            des.setText(item.getString(2));
            TextView pre=(TextView)dialogView.findViewById(R.id.textView31);
            pre.setText(item.getString(3));
            TextView fee=(TextView)dialogView.findViewById(R.id.textView32);
            fee.setText(item.getString(5));


            AlertDialog alertDialog = dialogBuilder.create();
            alertDialog.show();

我的alert_label_editor的xml代码...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="10dp"
android:paddingBottom="20dp">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:text="TextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView29"
            android:layout_weight="1"
            android:gravity="center"
            android:textSize="24sp"
            android:layout_marginBottom="10dp"
            android:textStyle="normal|bold" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:text="Description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView27"
            android:layout_weight="2" />

        <TextView
            android:text="TextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView28"
            android:layout_weight="1" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:text="Prescription"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView30"
            android:layout_weight="2" />

        <TextView
            android:text="TextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView31"
            android:layout_weight="1" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:text="fee"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView33"
            android:layout_weight="2" />

        <TextView
            android:text="TextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView32"
            android:layout_weight="1" />
    </LinearLayout>
</LinearLayout>

如何使用layout-inflatter解决此问题?

4 个答案:

答案 0 :(得分:1)

在里面使用scrollview ...

 <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:text="Description"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/textView27"
                    android:layout_weight="2" />

                <TextView
                    android:text="TextView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/textView28"
                    android:layout_weight="1" />
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:text="Prescription"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/textView30"
                    android:layout_weight="2" />

                <TextView
                    android:text="TextView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/textView31"
                    android:layout_weight="1" />
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:text="fee"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/textView33"
                    android:layout_weight="2" />

                <TextView
                    android:text="TextView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/textView32"
                    android:layout_weight="1" />
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

答案 1 :(得分:0)

alertDialog,show()

之后使用此功能
alertDialog.show();
alertDialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

如果上述方法无效,请尝试此

WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
alertDialog.show();
alertDialog.getWindow().setAttributes(lp);

答案 2 :(得分:0)

汤姆

您可以将所有视图放在scrollview中..

像这样

<Scrollview
android:layout_width="match_parent"
android:layout_height="match_parent">

  <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView 1/>

            <TextView 2/>
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView 1/>

            <TextView 2/>
        </LinearLayout>
           ..
           ..
           ..
          //add layout as your requirements

    </LinearLayout>    
 </Scrollview>

答案 3 :(得分:0)

在此尝试此代码我使用了第一个相对布局,然后是线性布局。下面是使用警告对话框显示弹出窗口的自定义布局。它适用于我,并与内容动态协作。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="30dp"
    android:background="@android:color/transparent"
    android:gravity="center">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="30dp"
        android:background="#FFFFFF"
        android:gravity="center"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:gravity="right"
            android:orientation="vertical">

            <TextView
                android:id="@+id/text_head"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginBottom="10dp"
                android:layout_marginRight="5dp"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="40dp"
                android:text=""
                android:textColor="@color/colorSecondary"
                android:textSize="25sp"
                android:textStyle="bold"
                android:fontFamily="@string/font_family_universal"
                />


            <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fillViewport="true">

                <WebView
                    android:id="@+id/textDescription"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="#00000000"
                    android:ems="10"
                    android:gravity="top"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:paddingTop="10dp"
                    android:textAlignment="viewEnd"
                    android:textColor="@color/black"
                    android:textSize="20dp"
                    android:fontFamily="@string/font_family_universal"
                    android:textStyle="normal"
                    >

                </WebView>
            </ScrollView>

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_gravity="center"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="3dp"
                android:background="#B2B2B2"
                android:scrollY="@dimen/activity_vertical_margin" />

        </LinearLayout>
    </LinearLayout>

    <ImageView
        android:id="@+id/imageCloseBtn"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="20dp"
        android:layout_marginTop="30dp"
        android:backgroundTint="@color/black"
        android:src="@drawable/sky_circle" />

    <TextView
        android:id="@+id/myImageViewText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageCloseBtn"
        android:layout_alignTop="@+id/imageCloseBtn"
        android:layout_alignRight="@+id/imageCloseBtn"
        android:layout_alignBottom="@+id/imageCloseBtn"
        android:layout_margin="1dp"
        android:gravity="center"
        android:text="X"
        android:textSize="20dp"
        android:textStyle="bold"
        android:textColor="#000000" />
</RelativeLayout>

请查看此示例代码,并按照布局的顺序使用和使用换行内容