2011-08-30 5 views
9

사용자 지정 AlertDialog을 만들려고하는데 레이아웃에 두 개의 단추가 있습니다. 그러나 버튼 레이아웃이 너무 길면 첫 번째 단어 만 표시됩니다. 이미 xml singleLine = "false",하지만 아무것도 설정했습니다.단추 텍스트에 여러 줄이 없음

또한 코드의 줄 수 (이 경우 2)를 설정했습니다. 그러나 텍스트가 길지 않으면 단추가 크게 커지지 않고 내용을 래핑합니다.

내가하고 싶은 것은 버튼의 텍스트 줄을 끊음으로써 너무 길더라도 버튼이 전체 텍스트를 감싸는 것, 그리고 전체 버튼을 감싸기 때문에 왼쪽 버튼이 더 큰 높이가되면 텍스트의 경우 측면의 버튼은 같은 높이 여야합니다. 안드로이드가 자동으로 그 일을하는 것을 안다. 왜 그런 일이 일어나지 않는지 나는 모른다.

아래의 이미지에서 버튼의 텍스트는 "테스트 버튼입니다"이지만 텍스트를 자르고 내용을 감싸지 않고 내용을 감싸지 않습니다. 당신의 무게 속성을 사용했기 때문에

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_root" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:minWidth="280dip" > 

    <LinearLayout 
     android:id="@+id/dialogTitleLayout" 
     android:orientation="vertical" 
     android:background="@drawable/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <TextView 
      style="@style/DialogText.Title" 
      android:id="@+id/dialogTitle" 
      android:paddingBottom="5dp" 
      android:paddingTop="5dp" 
      android:paddingLeft="8dip" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

    </LinearLayout> 

    <LinearLayout  
     android:id="@+id/dialogContentLayout" 
     android:orientation="vertical" 
     android:background="@drawable/center" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <TextView 
      style="@style/DialogText" 
      android:id="@+id/dialogContent" 
      android:layout_width="270dip" 
      android:layout_height="wrap_content" 
      android:paddingLeft="10dp" 
      android:paddingTop="10dp" /> 

<LinearLayout 
     android:id="@+id/buttonsLayout" 
     android:orientation="horizontal" 
     android:gravity="center_horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:paddingTop="10dp" >  
     <Button 
      android:id="@+id/neutralButton" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@drawable/button" 
      android:textColor="#FFFFFF"   
      android:paddingTop="8dp" 
      android:paddingBottom="8dp"    
      android:layout_gravity="center_horizontal" 
      android:layout_marginRight="90dp" 
      android:layout_marginLeft="90dp" 
      android:layout_marginBottom="10dp" 
      android:singleLine="false" />  
     <Button 
      android:id="@+id/positiveButton" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/button" 
      android:textColor="#FFFFFF"    
      android:paddingTop="8dp" 
      android:paddingBottom="8dp" 
      android:paddingLeft="10dp" 
      android:layout_weight="1" 
      android:paddingRight="10dp" 
      android:layout_margin="10dp" 
      android:singleLine="false" />  
     <Button 
      android:id="@+id/negativeButton" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/button" 
     android:textColor="#FFFFFF"    
     android:paddingTop="8dp" 
     android:paddingBottom="8dp" 
     android:paddingLeft="10dp" 
     android:layout_weight="1" 
     android:paddingRight="10dp" 
     android:layout_margin="10dp" 
     android:singleLine="false" />  
    </LinearLayout> 
</LinearLayout> 
</LinearLayout> 

답변

14

편집하여 버튼 속성 ..

<Button 
     android:id="@+id/neutralButton" 
     android:layout_width="wrap_content" 
     android:background="@drawable/button" 
     android:textColor="#FFFFFF"   
     android:textSize="10dp"     
     android:layout_gravity="center_horizontal" 
     android:singleLine="true" /> 
+0

왜 singleLine = "true"?? 버튼의 텍스트 줄을 어긋나게하고 싶습니다. – rogcg

+0

u를 singleline = "true"로 설정하면 전체 텍스트가 한 줄로 만 표시되고 반대로 설정하면 false로 설정됩니다. 버튼이 textsize가 너무 길고 버튼 너비가 텍스트에 비해 작을 수 있습니다. 두 가지 옵션이 있습니다. 랩 콘텐츠 또는 텍스트 크기를 두 개 작게 설정하여 버튼 폭을 늘릴 필요가 있습니다. –

+0

하지만 텍스트 크기가 너무 길더라도 텍스트 줄을 끊어야합니다. 그리고 버튼의 폭은 fill_parent입니다. – rogcg

3

그것은 아마도 :

enter image description here 다음

이 레이아웃의 XML은 다음과 같습니다

은 어떻게 보이는지의 스크린 샷입니다 버튼.
android:layout_weight="1" 

은 버튼에 무게를 제거하고 버튼에

android:layout_width="wrap_content" 

을 설정합니다. 나는 그것이 그것을해야한다고 생각한다.

작동 여부를 알려주십시오.

+0

폭 wrap_content을 설정하면은, doenst 버튼은 동일한 폭을 가지고있다. 나는 같은 폭을 유지하고 싶다. 이렇게하면 긴 텍스트가 가장 큰 버튼을 다른 버튼보다 크게 만들고 두 번째 버튼의 텍스트 마지막 문자를 숨 깁니다. 나는 그것을 수평으로 만드는 대신에 버튼 텍스트의 줄을 끊기를 원한다. 어쨌든 Thx. – rogcg

+0

단추와 TextView가 포함 된 FrameLayout을 사용하여 사용자 지정보기를 만들어야 할 것입니다. 버튼 가장자리에 닿지 않도록 TextView에 약간의 패딩을 제공하십시오. – Umesh

5

android:singleLine="true"이되지 않습니다. 사용이 대신 :

android:maxLines="1" 
관련 문제