3

Android アプリの ListView の項目の左側にチェック ボックスがあり、その後にテキストが続き、その後にボタンが続くようにしたいと思います。チェックボックスとボタンをテキストに合わせてベースラインにしたいと思います。これを実現するために、3 つすべてを、デフォルトでアイテムのベースラインを揃えようとする LinearLayout に配置します。複数行のテキストの一番下の行が常に切り取られることを除いて、これはうまく機能します。

これがどのように見えるかの例です:

問題の例

StackOverflow には、TextView に layout_gravity = "fill" を設定するという提案された解決策に関する関連する質問がありますが、ベースラインの配置が無効になるため、目的が無効になります。ベースラインの位置合わせを維持できるようにするこの問題の解決策はありますか? これはかなり基本的な問題のように思えますが、多くの人が遭遇するはずです。

私が見つけた他の唯一の解決策は、テキストビューの下部にパディングを追加することですが、これはハックであり、フォントサイズに対して堅牢ではないようです. フォント サイズに基づいてコードからプロシージャルにパディングを設定できますが、正しい値を取得するのは難しいようです。

問題を示すサンプル レイアウトを次に示します。

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="8dp"
    android:paddingTop="8dp"
    android:baselineAligned="true">

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="9dp"
        android:layout_marginRight="8dp"
        android:textSize="16sp"/>

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Woah, this is a long text line, enough that tit has to wrap to multiple lines, thus demonstrating our problem.  In fact, it wraps to multiple lines!  So many lines!  I hope they all show up correctly!"
            android:textSize="16sp"/>

    <FrameLayout
        android:layout_width="40dp"
        android:layout_height="match_parent">

        <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="12dp"
                android:src="@drawable/ic_note_check_delete"/>
    </FrameLayout>
</LinearLayout>
4

0 に答える 0