0

2 つの異なるヘッダーに割り当てられた 3 つの異なる値、つまり、1 つの値を持つ最初のヘッダーと 2 つの値を持つ 2 つ目のヘッダーを表示したい

私のアプローチは、「ヘッダーの線形レイアウト」を 40/60 に分割し、「値の線形レイアウト」を 40/30/30 に分割することです。境界線で始まるテキストを表示しないようにするために、どこにでもandroid:layout_marginLeft="15dp"in を配置したので、最終的には比例したままになります。

私の XML では、次のように宣言します。

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView 
        android:layout_weight="4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:text="@string/txt_price_chf"
        />
    <TextView 
        android:layout_weight="6"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:text="@string/txt_price_offshore_chf"
        />
</LinearLayout>

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView android:id="@+id/tv_price_ch"
        android:layout_weight="4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:text="Value1"
        />

    <TextView android:id="@+id/tv_price_off_chf"
        android:layout_weight="3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:text="Value2"
        />

    <TextView android:id="@+id/tv_price_off_eur"
        android:layout_weight="3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:text="Value3"
        />
</LinearLayout>

結果は次の出力です。

ここに画像の説明を入力

「Price offshore:」-TextView と「Value2」-TextView が一致しないのはなぜですか? 「オフショアの価格」がstrings.xmlに保存されていることに注意してください。空白などのエラーはありません。最初は が原因かと思いましたandroid:layout_marginLeft="15dp"が、

  • 「dp」は特定の解像度に対する相対値であることをどのように理解したか(したがって、分割はこれにandroid:layout_weigth影響を与えるべきではありません)

  • 余白を削除しても、まだ整列していません。

誰かアイデアはありますか?明らかなことを見落としていますか?

4

3 に答える 3

1
<TextView 
        android:layout_weight="4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="-10dp"
        android:text="@string/txt_price_chf"
        />

これはあなたのために働くでしょう...

于 2012-06-14T11:33:15.573 に答える
0

しかし、実際にはあなたがすべきことではありませんLinearLayout

を使用することをお勧めしRelativeLayoutます。そこでは、これら2つを揃える必要があると言えます。

この特定のケースでは詳細を掘り下げることなく、marginRight、パディングなど、または単に等幅フォント以外の副作用のいずれかである可能性があります。

于 2012-06-14T11:12:27.897 に答える
0

または別の代替手段は次のとおりです。

        <LinearLayout
       android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_weight=".60"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="txt_price_chf" />

    <TextView
        android:id="@+id/tv_price_ch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Value1" />
    </LinearLayout>


      <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_marginLeft="10dp"
          android:layout_weight=".40"
          android:orientation="vertical" >

        <TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="txt_price_offshore_chf" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/tv_price_off_chf"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Value2" />

        <TextView
            android:id="@+id/tv_price_off_eur"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Value3" />
    </LinearLayout>
</LinearLayout>
于 2012-06-14T11:39:46.760 に答える