2012-01-02 7 views
1

私は、ボタンを描く行うと、私はXMLで希望のデザインのAndroidレイアウトを選択するにはどうすればいいですか?

<?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" > 


    <LinearLayout 
     android:id="@+id/titleRowId" 
     android:layout_width="fill_parent" 
     android:layout_height="45dip" 
     android:background="@drawable/segment_bar_bg" 
     android:gravity="center_vertical|center_horizontal" 
     android:orientation="horizontal" > 

     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" > 

       <Button 
       android:id="@+id/backBtn" 
       android:layout_width="wrap_content" 
       android:layout_height="32dip" 
       android:layout_centerVertical="true" 
       android:layout_marginLeft="5dip" 
       android:background="@drawable/bar_btn_bg" 
       android:padding="0dip" 
       android:text="Cancel" 
       android:textColor="#FFF" /> 

       <Button 
       android:id="@+id/addBtn" 
       android:layout_width="wrap_content" 
       android:layout_height="32dip" 
       android:layout_centerVertical="true" 
       android:layout_marginLeft="250dip" 
       android:background="@drawable/bar_btn_bg" 
       android:padding="0dip" 
       android:text="Done" 
       android:textColor="#FFF" /> 

       <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 
        android:gravity="center_vertical|center_horizontal" 
        android:text="Convert Amount" 
        android:textColor="#FFFFFF" 
        android:textSize="20sp" 
        android:textStyle="bold" /> 

     </RelativeLayout> 
</LinearLayout> 

を以下のように上記バーとボタンを作っenter image description here

以下のように私は、イメージを持っているが、次の設計によると、私はaligmentsで問題に直面し、私は

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

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:gravity="right|top" 
     binding:text="FormattedDisplay" 
     android:text="Value" 
     android:textSize="45dip" /> 

    <TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:stretchColumns="0,1,2"> 

     <TableRow > 

      <Button 
       binding:onClick="Number7" 
       android:text="7" /> 

      <Button 
       binding:onClick="Number8" 
       android:text="8" /> 

      <Button 
       binding:onClick="Number9" 
       android:text="9" /> 
     </TableRow> 

     <TableRow > 

      <Button 
       binding:onClick="Number4" 
       android:text="4" /> 

      <Button 
       binding:onClick="Number5" 
       android:text="5" /> 

      <Button 
       binding:onClick="Number6" 
       android:text="6" /> 
     </TableRow> 

     <TableRow > 

      <Button 
       binding:onClick="Number1" 
       android:text="1" /> 

      <Button 
       binding:onClick="Number2" 
       android:text="2" /> 

      <Button 
       binding:onClick="Number3" 
       android:text="3" /> 
     </TableRow> 

     <TableRow > 

      <Button 
       android:layout_span="2" 
       binding:onClick="Number0" 
       android:text="0" /> 

      <Button 
       binding:onClick="Dot" 
       android:text="." /> 
     </TableRow> 

     <TableRow > 

      <Button 
       binding:onClick="Equal" 
       android:text="Convert" /> 
     </TableRow> 
    </TableLayout> 

</LinearLayout> 

に従うが、それは正しく

をボタンを合わせないように、それらを表示するためのTableLayout、および行を使用されるように

問題を解決して希望の出力を得るにはどうすればよいですか?

レイアウトを選択する方法を教えてもらえれば、適切な出力を得ることができますか?

XML出力を示し

enter image description here

+0

ご希望何ですが出力? –

+0

与えられた画像として、私はそのようにしたい@RajdeepDua –

+0

どのように2つのXMLファイルが関連していますか? –

答えて

3

はあなたのConvert ButtonTableLayoutの取り出し、などTableLayoutLinearLayout内の最後の場所でそれを貼り付けます。

<LinearLayout ... > 
    <TextView/> 
    <TableLayout> 
     <TableRows etc> 
    </TableLayout> 
    <Button android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     binding:onClick="Equal" 
     android:text="Convert" /> 
</LinearLayout> 

、これは私の結果与えている:

ScreenShot

+2

変換ボタンは、ボタンには属性 'android:layout_span = "3" 'しかない必要があるところにとどまることができます。 – Flo

+0

ありがとうございます。私はOPもそれを考慮すべきだと思う。 –

+0

ありがとう:-)、どちらもうまくいって、スパン3、そしてtableLayout :-) –

0

あなたのXMLレイアウトファイルを開き、オープングラフィカルなレイアウトタブ、後のコード

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

</RelativeLayout> 

の下に追加し、所望の位置に所望のウィジェットを追加します。必要に応じてすべてのアイテムを手に入れることができます(例:添付した上の画像のように)。これを試して。これは大きなレイアウトの正しい方法です。

+0

それは異なるデバイスで問題になるでしょうか? –

0

すべてのボタンの幅が同じではないので、RelativeLayoutを使用することをお勧めします。 RelativeLayoutを使用すると、各要素に他の要素に関連するレイアウト内の配置方法を伝えることで、レイアウトを定義できます。 android:layout_toLeftOfまたはandroid:layout_belowのような相対レイアウト内のビューにattributesを適用して、位置を定義することができます。

+0

しかし、ボタンの幅はどうすればいいでしょうか、私は手作業で与えて、別のデバイスでは、出力が異なります。 –

+0

Mh okです。次に、各行の要素を水平方向のLinearLayoutに配置し、weight属性を使用して作業します。 weight属性を使用すると、既存のスペースを特定の比率で共有する必要があることをビューに伝えることができます。 – Flo

+0

私はアンドロイドのレイアウトの構造についてはっきりしていないので、2行か3行のデモを行うことができますか、ちょうどコード、私はそれが動作しているかのように表示されます –

関連する問題