2011-01-23 7 views
1

私はかなりアンドロイドに慣れていて、レイアウトにいくつか問題があります。以下は私がレイアウトを見せたいものの近似値です。 (私は最初に画面の下にリストを表示して、ユーザーがそれを見るためにスクロールできるようにしたいと思います)。しかし、現在のコードでは、すべてのビューを左に置くと、画面の半分私はすべての幅がfill_parentに設定されています。Androidでのレイアウトの問題

また、このレイアウトは私のカスタムビューの座標系を台無しにしているようです。通常これは大きな問題ではありませんが、この場合はそのビューを使用して画像を描画し、画像が間違った場所に表示されます。誰もこれらの問題を解決する方法を知っていますか?あなたは手段を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

は、ここに私のコードです。それは、「私の親と同じくらい大きい」という意味です。また、なぜ2つのネストされた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

あなたが言ったようにウエイトを使用して問題を修正しましたが、幅を0に設定すると、2人の子供が見えなくなりました(幅がないので) –

+0

@schwiz:TableLayoutはLinearLayoutで実装されています。 TableLayout/TableRowは、重みbtwも使用できます。 –

0

あなたがアンドロイドを入力しているためである:あなたが水平方向のLinearLayoutを使用し、それぞれの子(TableLayoutとカスタムビュー)0dipの幅と1のlayout_weightを与えるべきで均等に二つに画面を分割するには:あなたのEditTextsのlayout_span = "2"これらをすべて削除すると、より正常に動作します。

次に、EditTextの幅を200dpに設定することで、左側を制御できます。 EditTextの右余白を使用して、左の列を制御することもできます。

カスタムビューキャンバス内の座標は、その右上隅に0,0から始まります。

関連する問題