2011-01-23 5 views
1

나는 안드로이드를 처음 접했고 레이아웃에 약간의 문제가있다. 다음은 내가 원하는 레이아웃의 근사치입니다. (나는 사용자가 그것을보기 위해 아래로 스크롤 할 수 있도록 처음에 화면 아래에 목록을 원합니다.) 그러나 현재 내 코드는 모든 뷰를 왼쪽에 절반 만 대신 4 분의 1 화면 걸립니다. , 필자는 모든 너비가 fill_parent로 설정되어있다.안드로이드에서의 레이아웃 문제

또한이 레이아웃은 내 사용자 정의보기에서 좌표계를 망칠 것 같습니다. 일반적으로 이것은별로 문제가되지 않지만,이 경우 뷰를 사용하여 그림을 그리고 그림이 잘못된 위치에있게됩니다. 아무도 이러한 문제를 해결하는 방법을 알고 있습니까? 당신이 수단을 fill_parent 어떤 오해 것 같습니다

<?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"> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:orientation="vertical"> 
<TableRow> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="fill_parent" android:orientation="vertical" 
android:layout_width="fill_parent"> 
<TableRow> 
<TextView android:text="Resultant Force" android:id="@+id/resForceTitle" 
    android:textSize="25dip" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:padding="3dip" 
    android:gravity="center" android:layout_span="2" /> 
</TableRow> 
<TableRow> 
<TextView android:id="@+id/magText" android:text="Magnitude (N) =" 
    android:textSize="15dip" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:padding="3dip" 
    android:gravity="center_vertical" android:layout_span="2" /> 
</TableRow> 
<TableRow> 
<EditText android:id="@+id/magnitude" android:inputType="numberDecimal" 
    android:layout_width="fill_parent" android:padding="3dip" 
    android:layout_height="fill_parent" android:layout_span="2" /> 
</TableRow> 
<TableRow> 
<TextView android:id="@+id/dirText" android:text="Angle (deg) =" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:textSize="15dip" android:gravity="center_vertical" 
    android:layout_span="2" /> 
</TableRow> 
<TableRow> 
<EditText android:id="@+id/direction" android:inputType="numberDecimal" 
    android:layout_height="fill_parent" android:padding="3dip" 
    android:layout_width="fill_parent" android:layout_span="2" /> 
</TableRow> 
<TableRow> 
<Button android:id="@+id/pushButton" android:text="Add Force" 
    android:layout_height="fill_parent" android:padding="3dip" 
    android:layout_width="fill_parent" /> 
<Button android:id="@+id/clearButton" android:text="Clear" 
    android:layout_height="fill_parent" android:padding="3dip" 
    android:layout_width="fill_parent" /> 
</TableRow> 
</TableLayout> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="fill_parent"> 
<android.physicsengine.AxisDrawing 
android:id="@+id/image" android:layout_width="fill_parent" 
android:layout_height="fill_parent" /> 
</FrameLayout> 
</TableRow> 
</TableLayout> 
<ListView android:id="@android:id/list" android:layout_height="wrap_content" 
android:padding="3dip" android:layout_width="fill_parent" 
android:clickable="false" /> 
<TextView android:id="@android:id/empty" android:text="Add Forces to List Components" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:textSize="15dip" android:gravity="center_vertical" /> 
</LinearLayout> 

답변

4

당신의 XML의 모양에서 : alt text

여기 내 코드입니다. 그것은 "부모처럼 크게"라는 뜻입니다. 또한, 왜 두 개의 중첩 된 TableLayouts를 사용하고 있습니까?

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <TableLayout 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_height="wrap_content"> 
      ... 
    </TableLayout> 
    <android.physicsengine.AxisDrawing 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_height="wrap_content" /> 
</LinearLayout> 
+0

가중치가있는 LinearLayout이 TableLayouts보다 나은 선택이 아니었던 때를 보지 못했습니다. – schwiz

+0

당신이 말했던 것처럼 가중치를 사용하여 문제를 해결했지만 width를 0으로 설정하면 dip이 두 개의 자식을 보이지 않게 만들었습니다. (너비가 없기 때문에) –

+0

@schwiz : TableLayout은 LinearLayout으로 구현되었으며 그 이상을 수행합니다. TableLayout/TableRow는 또한 가중치 btw를 사용할 수 있습니다. –

0

당신이 안드로이드를 입력하기 때문이다 : 당신은 수평의 LinearLayout을 사용하고 각 아동합니다 (TableLayout을 및 사용자 정의보기) 0dip의 폭과 1의 layout_weight를 제공한다 고르게 두 화면을 분할하려면 : layout_span = "2"EditTexts에 있습니다. 제거하면 모두 정상적으로 작동합니다.

예를 들어 EditText의 너비를 200dp로 설정하여 왼쪽을 제어 할 수 있습니다. EditText의 오른쪽 여백을 사용하여 왼쪽 열을 제어 할 수도 있습니다.

사용자 정의보기 캔버스의 좌표는 맨 위 오른쪽 구석에 0,0부터 시작합니다.