0

I am trying to design a custom dialog. The problem I met was..the background of the textview ,which is the body of the dialog can't change whenever the text get more line .. wrap_content didn't work ....

PS (there are there part , title , content, buttons ) ( title and content are two TextView with two image as background)

one line is fine

enter image description here

but when lines increased... they were eaten !!

enter image description here

if I use wrap_content ... it goes too big ! https://www.dropbox.com/s/in78b8gg0hfkfxh/toobig.png

here is the code of xml `

android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
>

<LinearLayout
    android:id="@+id/dialog"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"       
    android:paddingTop="120dip" 
  >

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

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/title"
            android:text="Title"
            style="@style/TitleStyle"
            android:gravity="bottom|center_horizontal"
            android:paddingBottom="15dip"
            />

    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="89dip"
        android:background="@drawable/content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="L\na\ny\no\nu\nt\n"
            android:gravity="center"
            style="@style/TextStyle"
            android:paddingRight="20dip"
            android:paddingLeft="20dip"             
            android:paddingTop="10dip"

              />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:gravity="center"
        android:padding="0dip"
        android:paddingTop="0dip" >

        <Button
            android:id="@+id/dialog_button_cancel"
            android:layout_width="0dip"
            android:layout_height="51dip"
            android:layout_weight="0.50"
            style="@style/BtnStyle"
            android:background="@drawable/btn_action"
            android:src="@drawable/btn"
            android:text="取消"             

            android:gravity="center"
             />

        <Button
            android:id="@+id/dialog_button_ok"
            android:layout_width="0dip"
            android:layout_height="51dip"
            android:layout_weight="0.50"
            android:background="@drawable/btn_action"
            android:src="@drawable/btn"
            android:layout_marginLeft="10dip"  
            style="@style/BtnStyle"       
            android:text="確定"
             android:gravity="center"
              />
    </LinearLayout> 



</LinearLayout>

`

wennnt
  • 41
  • 11

1 Answers1

0

For second (content) TextView wrapper (LinearLayout) try to use wrap_content instead of fixed layout height 89dip:

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

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="L\na\ny\no\nu\nt\n"
        android:gravity="center"
        style="@style/TextStyle"
        android:paddingRight="20dip"
        android:paddingLeft="20dip"             
        android:paddingTop="10dip"

          />
</LinearLayout>

Edit: If the problem is in the image (by the image IMHO you mean white rectangle which wraps title and content views) try to set up rectangle in background in XML instead of an image usage you use for now:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listview_background_shape">
    <stroke android:width="2dp" android:color="#ffffff" />
    <padding android:left="2dp"
        android:top="2dp"
        android:right="2dp"
        android:bottom="2dp" />
    <corners android:radius="5dp" />
    <solid android:color="#8000000" /> <!-- transparent -->
</shape>

Details here: Can I draw rectangle in XML?

Community
  • 1
  • 1
Yehor Nemov
  • 907
  • 2
  • 16
  • 31
  • then it goes too big :( is the problem happen on the image? – wennnt Mar 19 '14 at 15:49
  • You could leave wrapper height fixed but add `android:maxLines = "AN_INTEGER"` and `android:scrollbars = "vertical"` properties to the second (content) TextView xml. It has to make your content scrollable. – Yehor Nemov Mar 19 '14 at 15:55
  • Possible content is eaten by the image. Try to set up layout without TextViews backgrounds, get what you want to achieve and add backgrounds after all. It helps you understand a place from where the flaws are come. – Yehor Nemov Mar 20 '14 at 07:52
  • if the problem is the image, what can i do ? – wennnt Mar 20 '14 at 15:28
  • You could set up an image like background in XML instead of the real image usage. See answer update above. – Yehor Nemov Mar 20 '14 at 16:25
  • I use padding to solve the problem :( though it may have some trouble when lines up to more than 15 ... while the space really increased, the image does as well . I tried to add what you said, but the height seems can't be auto changed ... if you have other ways please tell me , you give me a lot help , really thanks ! – wennnt Mar 21 '14 at 18:31