1

私は Andorid Metrics and Grids ( http://developer.android.com/design/style/metrics-grids.html ) を読んでいますが、今はレイアウトの見栄えを良くしようとしています。TextEdit とボタンの 2 つの要素を持つ TableRow があります。

<TableRow android:id="@+id/tableRow2" android:layout_width="match_parent" android:layout_height="match_parent">
<EditText
    android:id="@+id/personDOB"
    android:hint="Date of birth"
    android:inputType="date" />

<ImageButton
    android:id="@+id/openCalendar"
    android:layout_width="48dp"
    android:layout_height="wrap_content"
    android:background="@drawable/mybutton_background"
    android:contentDescription="@string/selectdate"
    android:cropToPadding="true"
    android:onClick="selectDate"
    android:src="@drawable/ic_datepicker"/>
</TableRow>

私のボタンは32x32です(したがって、48dpのリズムのために各辺に8dpのマージンを追加できます)が、TableRowでは幅の3倍のようです。ボタンの layout_width = 48dp (上記のように) を作成し、コンテンツをラップし、width=0px と weight でいくつかの実験を試みましたが、これはすべて役に立ちません。ボタンで固定サイズにする必要があり、他のすべての行スペースは EditText で使用する必要があります。

4

1 に答える 1

1

次のレイアウトをあなたのものに置き換えてください。

<TableRow
    android:id="@+id/tableRow2"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:id="@+id/personDOB"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:hint="Date of birth"
        android:inputType="date" />

    <ImageButton
        android:id="@+id/openCalendar"
        android:layout_width="48dp"
        android:layout_height="wrap_content"
        android:background="@drawable/mybutton_background"
        android:contentDescription="@string/selectdate"
        android:adjustViewBounds="true"
        android:cropToPadding="true"
        android:onClick="selectDate"
        android:scaleType="centerInside"
        android:src="@drawable/ic_datepicker" />
</TableRow>
于 2013-08-26T13:12:29.043 に答える