私はListViewアイテムのかなり単純なレイアウト(Linear)を持っています。水平に配置された3つのウィジェット:2つのTextViewアイテム、次にButton。しかし、すべての3のlayout_heightがwrap_contentであっても、ボタンに使用された値は、ListItemを必要以上に拡張するように思えます。しかし、単にlayout_heightの値を25dpに変更すると、これはなくなります。LayoutItemがwrap_contentに変更されたときにListItemの高さ(LinearLayout)が高くなるのはなぜですか?
なぜボタンのwrap_contentにこのような影響があり、どのように停止するのですか?
ウィジェットの寸法を示す下のスクリーンショットの背景色に注目してください。 2つの画像の違いは、私のXML(下部)でButtonのlayout_heightがwrap_contentから25dpに変更されていることです。ボタンのlayout_heightため
<?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:orientation="horizontal"
>
<TextView
android:id="@+id/tvTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_gravity="left"
android:text="0."
android:textSize="18sp"
android:maxLines="1"
android:layout_weight=".15"
android:background="@color/LightGreen"
/>
<TextView
android:id="@+id/tvName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="left"
android:text=""
android:textSize="18sp"
android:maxLines="1"
android:layout_weight=".55"
android:background="@color/LightBlue"
/>
<Button
android:id="@+id/btnMyButton"
android:layout_width="0dp"
android:layout_height="25dp"
android:gravity="right"
android:layout_gravity="right"
android:textColor="@color/CornflowerBlue"
android:text="Questions"
android:textSize="16dp"
android:maxLines="1"
android:layout_weight=".3"
android:background="@color/black"
>
</Button>
</LinearLayout>
使用wrap_contentは:ボタンのlayout_heightため
ハードコーディング25dp
:
案の定。奇妙な。どうしてAndroidのジャッキーリングがずっと詰まっているのでしょうか、なぜボタンではなく他のウィジェットではないのでしょうか? – Alyoshak
Uxの問題だと思います。原因ボタンはクリック可能になっていて、内部に表示されているテキストです。デフォルトのパディングが追加されています。 – rafsanahmad007
これは多くのデフォルトパディングです。 – Alyoshak