2011-03-02 7 views
1

저는 Android 개발을 처음 시작한 사람입니다. 해야한다고 생각하지만 (나를 위해, 어쨌든) 생각하지 않습니다. 화면의 하단 (? 중력) 상단 행 복용에 도킹되는2 행이있는 전체 화면 안드로이드 레이아웃

--------------------- 
|     | 
|     | 
|     | 
|     | 
|     | 
|  Main View  | 
|     | 
|     | 
|     | 
|     | 
|     | 
--------------------- 
||btn a|  |btn b|| 
--------------------- 

전체 레이아웃이 맨 아래 행으로 화면을 작성해야합니다 : 아래의 멋진 아스키 아트는 내가 달성하기 위해 노력하고있어 레이아웃을 보여줍니다 나는 HTML에서 작업하는 경우

--------------------------- 
|       | 
|       | 
|  Main View  | 
|       | 
|       | 
--------------------------- 
||btn a|   |btn b|| 
--------------------------- 

이 쉽게 테이블 요소, 두 TR 함께 할 것 : 장치의 방향이 같을 것이다 변경, 즉 경우 (화면의 나머지 부분까지 그리고 유체해야 요소들 (행의 길이가 2 인 첫 번째 요소)과 두 번째 행에 두 개의 TD 요소가 있습니다 (두 번째 요소는 정렬 값이 오른쪽으로 설정됩니다). (웹 UI 사용자 인 readi 이것은 레이아웃에서 실제로 DIV 요소와 CSS를 사용합니다).

그래서, 내 문제는 사용 가능한 높이를 채우기 위해 첫 번째 행을 얻고 있습니다. 나는 자바 코드에서 이것을하는 간단한 알고리즘을 작성할 수 있지만 레이아웃을 위해 XML을 사용하는 것을 선호한다. 이 작업을 수행하는 쉬운 방법이 있습니까? 내 코드는 다음과 같습니다 :

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:stretchColumns="1"> 
    <TableRow> 
     <WebView android:id="@+id/site" 
      android:layout_span="3" /> 
    </TableRow> 
    <TableRow> 
     <Button android:id="@+id/back" 
      android:text="btn a" /> 
     <View android:id="@+id/filler" /> 
     <Button 
      aroid:id="@+id/forward" 
      android:text="btn b" /> 
    </TableRow> 
</TableLayout> 
+1

을이 밖으로 시도 relativelayout.html – Klaus

+0

이 문제에 대한 해결 방법이 많았지 만 그 중 많은 부분이 훌륭하게 작동한다고 확신하지만 그 중 하나만 시도해 본 결과 나에게 도움이되었습니다. 도와 주신 모든 분들께 감사드립니다. –

답변

4

무게가 올바른 선택이다, 나는 RelativeLayout의 정말 도움이 될 수 있다고 생각 (를 테스트)

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:stretchColumns="1"> 
    <LinearLayout android:layout_height="fill_parent" 
        android:layout_width="fill_parent" 
        android:id="@+id/linearLayout2" 
        android:layout_weight="1"> 
     <WebView android:layout_height="wrap_content" 
       android:id="@+id/site" 
       android:layout_width="wrap_content" /> 
    </LinearLayout> 
    <LinearLayout android:id="@+id/linearLayout1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"> 
     <Button android:layout_weight="2" 
       android:text="Button" 
       android:id="@+id/button1" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"></Button> 
     <Button android:layout_weight="2" 
       android:text="Button" 
       android:id="@+id/button2" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"></Button> 
    </LinearLayout> 
</TableLayout> 
+0

위대한, 이것은 완벽하게 작동했다. 감사. –

0

테스트 한 적이 없지만 이론적으로 작동합니다. 나는 컴퓨터 :)에 돌아가 자마자 그것으로 볼 것이다

<?xml version="1.0" encoding="UTF-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     > 
     <Button 
      android:id="@+id/btna" 
      android:layout_height="42dp" 
      android:layout_width="wrap_content" 
      android:layout_weight="1" 
      android:text="Button A"" 
     /> 
     <Button 
      android:id="@+id/btnb" 
      android:layout_height="42dp" 
      android:layout_width="wrap_content" 
      android:layout_weight="1" 
      android:text="Button B" 
     /> 
    </LinearLayout> 
</RelativeLayout> 
0

당신이 할 수 있었던 TableLayout을 죽겠다과 웹보기에 무게를 설정해보십시오 : 나는 이것을 테스트하지 않았습니다

<WebView 
    android:id="@+id/site" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" /> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    (**Button, filler View, Button go here**) 
</LinearLayout> 

하지만, 그것은 가깝습니다.

0

RelativeLayout을 사용하면 과용 된 것처럼 보입니다 (). layout_alignParentBottom은 항상 신뢰할 수있는 것은 아닙니다.

시도 :

<?xml version="1.0" encoding="UTF-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <WebView android:id="@+id/site" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"/> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <Button 
      android:id="@+id/btna" 
      android:layout_height="42dp" 
      android:layout_width="wrap_content" 
      android:text="Button A"> 
     <View android:id="@+id/filler" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_weight="1"/> 
     <Button 
      android:id="@+id/btnb" 
      android:layout_height="42dp" 
      android:layout_width="wrap_content" 
      android:text="Button B"/> 
    </LinearLayout> 
</LinearLayout> 

당신은 있는 LinearLayoutlayout_weight와 함께 많은 작업을 수행 할 수 있습니다. http://developer.android.com/resources/tutorials/views/hello- :

+0

layout_alignParentBottom을 항상 신뢰할 수없는 이유는 무엇입니까? RelativeLayout을 사용하면 두 개 이상의 중첩 된 LinearLayout을 피할 수 있습니다. – Adinia

+0

나머지 레이아웃에 따라 다릅니다. 예 : https://code.google.com/p/android/issues/detail?id=1394 과거에는 나에게 버그가 있었고 다른 레이아웃을 선호합니다. –

+0

실제로 링크에 감사드립니다. 가끔 까다로울 수 있다는 것에 동의하지만,이 경우에는 ListView가 없으므로 문제가 있어야한다고 생각하지 않습니다. 나에게 RelativeLayout은 많은 인라인 LinearLayouts보다 쉬운 것처럼 보이지만 실제로 전문가라고 말할 수는 없다. – Adinia

관련 문제