2011-05-02 3 views
2

나는이 내 안드로이드 응용 프로그램에서 다음 레이아웃 : (가) 중간에서 글고 치기로 하나의 전체 공간을 채우기 위해 확장 있도록Android에서 TableLayout의 Middle TableRow를 확장하는 방법은 무엇입니까?

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout android:id="@+id/widget41" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical"> 
<tablerow> 
    <Button android:id="@+id/button_when" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:padding="10px" 
     android:text="When"> 
    </Button> 
</tablerow> 
<tablerow> 
    <EditText android:id="@+id/text_description" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:padding="10px" 
     android:text="What happened?" android:textSize="18sp"> 
    </EditText> 
</tablerow> 
<tablerow> 
    <Button android:id="@+id/button_location" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:padding="10px" 
     android:text="Location"> 
    </Button> 
</tablerow> 

가 어떻게 내 레이아웃을 만들 수 있습니다 첫 번째 항목과 세 번째 항목에서 화면을 차지하지 않습니까?

답변

0

매우 간단합니다.

두 가지 방법

  1. 화면 밀도와 해상도를 발견 한 후 첫 번째와 마지막으로 필요한 공간의 양을 알 수있다. 표지까지

    내 개인적인 의견은 첫째로 이동하는 것입니다 전체 화면을 layout_height :

  2. 지금 단순히 android:layout_height="space which has been left"

또 다른 방법을 사용하여 중간 행으로 공간의 나머지 부분을 충당하는 것은 안드로이드를 변경하는 것입니다 하나는 화면 크기가 기기마다 다를 수 있으므로 안전하게 재생해야합니다.

그러나 코드가 작동하는지 확인 하시겠습니까? t은 (는) <tablerow>입니다. <TableRow>이어야합니다. 모든 태그에 android:layout_height and android:layout_width이 전달되지 않으면 레이아웃에 오류가 발생할 수 있습니다.

Play safe 그렇지 않으면 앱이 버그로 판명 될 것입니다.

도움이되기를 바랍니다.

+0

내 답을 살펴 봐야 할 수도 있습니다. – Martin

1

이 작업은 Varundroid의 제안보다 훨씬 간단하게 수행 할 수 있습니다. android.widget.TableRowandroid.widget.LinearLayout의 하위 클래스이므로 레이아웃에 필요한 모든 매개 변수를 가져옵니다. 요구되는 확장 할 때 설정 android:layout_weight는 일반적으로 필요하다고

<TableRow 
    android:layout_height='fill_parent' 
    android:layout_weight='1.0' 
    android:layout_width='fill_parent' 
    > 
    … 
    </TableRow> 

참고 : 그래서이 트릭을 할 것입니다.

관련 문제