0

以下のコードは、textview のテキストの下に緑色の下線を付けようとしています。これは 2.3.7 の電話では機能しませんが、新しいデバイスでは機能します。古いデバイスでは、テキストの下に緑色の下線が表示されません。layout_weight は古いデバイスでは機能しませんか? 同じことを達成するための他のトリックはありますか?

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:weightSum="1" >

            <TextView
                android:id="@+id/onText"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.8"
                android:background="#F21861"
                android:fontFamily="sans-serif-condensed"
                android:gravity="center"
                android:text="off"
                android:textAllCaps="true"
                android:textColor="#454545" />

            <ImageView
                android:id="@+id/underline"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.2"
                android:background="#00a950"
                android:contentDescription="@null" />
        </LinearLayout>
4

1 に答える 1

0

Soubhit Puri が提供するリンクは、より良い方法です。 Android、下線の色を EditText から動的に変更します

LinearLayout の高さを 25dp などの固定サイズに設定してから、Textview の高さを 22dp に、ImageView の高さを 3dp に設定することで簡単に修正できます。

または、以下のコードに従って、ImageView を削除し、LinearLayout の背景を 25 dp の緑に、Textview の高さを 22 dp に設定します。

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:background="#00a950" >

            <TextView
                android:id="@+id/onText"
                android:layout_width="match_parent"
                android:layout_height="22dp"
                android:background="@android:color/white"
                android:fontFamily="sans-serif-condensed"
                android:gravity="center"
                android:text="off"
                android:textAllCaps="true"
                android:textColor="#454545" />
    </LinearLayout>
于 2013-08-16T13:36:19.840 に答える