0

いくつかのデータを表示する必要がTableLayoutあります。各行には2つの列があります。最初の列にはフィールド名があり、2番目の列にはフィールド値があります。いずれかのフィールドをクリックすると、が表示されますEditText。私はを使用してそれを行いますViewSwitcher

TextView/の文字数が少ない場合EditTextは問題ありませんが、最初の行がいっぱいになると、最初の列(フィールド名)が狭くなり、2番目の列が広くなります。私はそれが起こらないようにしたいのです。列を常に同じサイズにしたいのです。

これは私のレイアウトです:

<TableLayout
    android:id="@+id/formLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textLicense"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/license"
            android:textSize="18sp"
            android:textStyle="bold" />

        <ViewSwitcher
            android:id="@+id/licenseSwitcher"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="3" >

            <TextView
                android:id="@+id/tvLicenseVariable"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:onClick="LicenseViewClicked"
                android:textSize="18sp" />

            <com.timeondriver.petrolcontrol.MySpinner
                android:id="@+id/spinnerLicense"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:prompt="@string/license_prompt" />
        </ViewSwitcher>
    </TableRow>

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/date"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/tvDateVariable"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:clickable="true"
            android:onClick="DateViewClicked"
            android:textSize="18sp" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp">

        <TextView
            android:id="@+id/textPlace"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/place"
            android:textSize="18sp"
            android:textStyle="bold" />

        <ViewSwitcher
            android:id="@+id/placeSwitcher"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="3" >

            <TextView
                android:id="@+id/tvPlaceVariable"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:onClick="PlaceViewClicked"
                android:textSize="18sp" />

            <EditText
                    android:id="@+id/editTextPlace"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                android:imeOptions="actionDone"
            android:maxLines="3"
                    android:inputType="textMultiLine"
                     />
        </ViewSwitcher>
    </TableRow>
</TableLayout>

場所データが短い場合のビューは次のようになります。

ここに画像の説明を入力してください

そして、これは、場所データの文字数が多すぎる場合(最初の行がいっぱい)のビューの外観です。

ここに画像の説明を入力してください

ライセンス、日付、時刻の行はサイズが制限されているため、問題ありません。場所データのある行は、文字数が多すぎる場合に列幅を変更する行です。列の幅を常に同じにするにはどうすればよいですか?

ありがとう!

4

1 に答える 1

2

問題は、layout_width と layout_weight を指定したことだと思います。十分なテキストを入力しないと、wrap_content で指定された layout_width が使用されているようです。十分なテキストを入力すると、指定された layout_weight よりも大きな幅に達するため、この時点で layout_weight 属性がカウントされます。列のサイズを常に同じにするには、layout_width を 0dpi に設定して、layout_weight 属性のみが使用されるようにします。次に、左の列のテキストに 1/4 から 3/4 が適合しないように見えるため、2 つの列の間に異なる比率を指定する必要があります。おそらく、2/5 から 3/5 のようなものを選択する必要があります。これは、layout_weight=2 を左の列に、3 を右の列に設定することを意味します。

于 2013-03-01T11:21:16.457 に答える