2012-11-07 4 views
0

필자는 아래 xml에 표시된 버튼 중 하나를 클릭하면 버튼의 텍스트가 한 줄 아래로 점프된다는 문제가 있습니다. 따라서 버튼이 1 줄이면 텍스트가 표시되지 않습니다. 버튼이 2 라인 인 경우 버튼의 버튼에 첫 번째 라인 만 표시됩니다.안드로이드 버튼 텍스트가 움직입니다.

onClick 메서드의 아무 것도 레이아웃을 변경하지 않습니다.

내가 버튼에 layout_width가 wrap_content로 변경하면 지금, 모든 것이 (When changing textview, the text on a button below the textview moves down. Help!에서 생각이있어) 잘 작동

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


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

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" > 

.. a few other layouts and controls that works fine 



     <TableLayout 
       android:id="@+id/tableLayout276" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 

       <TableRow 
        android:id="@+id/TableRow10" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="left" 
        android:gravity="center" 
        android:orientation="vertical" > 



        <Button 
         android:id="@+id/BtnRet" 
         android:layout_width="120dp" 
         android:layout_height="wrap_content" 
         android:text="Ret" 
         android:gravity="center" 
         android:textSize="18dp" />  

        <Button 
         android:id="@+id/BtnVisningsType" 
         android:layout_width="120dp" 
         android:layout_height="wrap_content" 
         android:text="Decimaltal" 
         android:gravity="center" 
         android:textSize="18dp" /> 

        <Button 
         android:id="@+id/BtnFunktioner" 
         android:layout_width="120dp" 
         android:layout_height="wrap_content" 
         android:text="Funktioner" 
         android:gravity="center" 
         android:textSize="18dp" />  
      </TableRow> 
     </TableLayout> 

.. a few other layouts and controls that works fine 


</LinearLayout> 
</ScrollView> 
</LinearLayout> 

을 heres XML - 지금 obviusly 같은 폭을 해달라고 버튼을 제외하고, 그리고 그것은 더러워 보입니다.

왜 이런 일이 발생하는지, 그리고 텍스트를 보관하고 단추의 크기를 결정할 수있는 방법에 대해 알 수 있습니까?

답변

2

이렇게하면 레이아웃이 복잡해 지지만 해결책이 될 수 있습니다.

표 행에 LinearLayout을 추가하고 가중치를 사용하여 버튼의 정확한 레이아웃을 제어하십시오. 이런 식으로 뭔가 :

<TableRow 
       android:id="@+id/TableRow10" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left" 
       android:gravity="center" 
       android:orientation="vertical" > 

    <LinearLayout android:layout_height="match_parent" 
        android:layout_width="match_parent" 
        android:weightSum="3" 
        android:orientation="horizantal"/> 

       <Button 
        android:id="@+id/BtnRet" 
        android:layout_weight="1" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:text="Ret" 
        android:gravity="center" 
        android:textSize="18dp" />  

       <Button 
        android:id="@+id/BtnVisningsType" 
        android:layout_weight="1" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:text="Decimaltal" 
        android:gravity="center" 
        android:textSize="18dp" /> 

       <Button 
        android:id="@+id/BtnFunktioner" 
        android:layout_weight="1" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:text="Funktioner" 
        android:gravity="center" 
        android:textSize="18dp" />  

    </LinearLayout> 

</TableRow> 

주의 사항 :

  • 줄 수 있음은 성능은
  • 는, 정확한 조정 오타에게
  • 테스트하지
  • 사용 패딩/마진을 실례 메모리에서 입력 된 히트 크기 조정

어안 또한 일한다.

+0

완전히 동의하십시오. 예를 들어 하드 코딩 된보기 크기를 사용하지 않으려 고합니다. android : layout_width = "120dp" –

+0

Ive에게이 질문이 몇 가지 있습니다. 첫 번째 : 당신의 제안은 선형 뷰입니다. "weigthsum"라인이있는 선형 레이아웃을 사용하면 버튼을 아래쪽 대신에 옆으로 조정할 수 있습니다. 그런 종류의 테이블 레이아웃을 망칠 수 있습니까? – user1285334

+0

두 번째 : 패딩/여백을 사용하여 단추의 크기를 조정하면 단추의 크기가 변하지 않습니까? 텍스트를 변경하면 어떻게됩니까? 나는 버튼들이 서로 같은 크기가되도록하고, 무슨 일이 일어나더라도 그 크기를 유지한다. (물론 텍스트가 길어지면 wrap_content 높이의 두 번째 줄이 생깁니다.하지만 괜찮습니다.) – user1285334

관련 문제