2

私はこのようにコーディングしようとしました

    <ImageView android:id="@+id/ivIcon"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:src="@android:drawable/ic_btn_speak_now" />

    <TextView
        style="@style/behindMenuItemLabel"
        android:text="Item0" />

しかし、それはこのように出力されます。それは同じ行にありません:(

ここに画像の説明を入力

私のxmlコード全体はこのようなものです。 (icon) itemアクティビティに移動するためにユーザーがクリックするセットになります。
したがって、それらをグループ化する必要があります。

<LinearLayout style="@style/behindMenuScrollContent"
    android:paddingTop="25dp" >

    <TextView
        style="@style/behindMenuItemTitle"
        android:text="Subject" />

    <TextView
        style="@style/behindMenuItemLabel"
        android:text="Item0" />

    <TextView
        style="@style/behindMenuItemLabel"
        android:text="Item1" />

    <TextView
        style="@style/behindMenuItemLabel"
        android:text="Item2" />

    <TextView
        style="@style/behindMenuItemLabel"
        android:text="Item3" />

    <TextView
        style="@style/behindMenuItemLabel"
        android:text="Item4" />

    <TextView
        style="@style/behindMenuItemLabel"
        android:text="Item5" />

    <TextView
        style="@style/behindMenuItemTitle"
        android:text="Subject2" />

    <TextView
        style="@style/behindMenuItemLabel"
        android:text="Item6" />

    <TextView
        style="@style/behindMenuItemLabel"
        android:text="Item7" />

    <TextView
        style="@style/behindMenuItemLabel"
        android:text="Item8" />

    <TextView
        style="@style/behindMenuItemLabel"
        android:text="Item9" />

    <TextView
        style="@style/behindMenuItemLabel"
        android:text="Item10" />


    <Button
        android:id="@+id/behind_btn"
        style="@style/behindMenuItemLabel"
        android:text="BUTTON" />

</LinearLayout>

更新: アイコンとテキストの間の余白は必要ありませんが、左だけに余白が必要です!

ここに画像の説明を入力

style.xml

<style name="behindMenuItemLabel">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_marginLeft">20dp</item>
    <item name="android:layout_marginBottom">4dp</item>
    <item name="android:textSize">30sp</item>
    <item name="android:textColor">#d2d2d2</item>
</style>
4

5 に答える 5

4

このようなことを試してください:

<TextView
    android:id="@+id/behindMenuItemLabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    android:layout_weight="40"
    android:drawablePadding="-5dp"
    android:gravity="center_vertical"
    android:text="Speak Now"
    android:textColor="#000000"
    style="@style/behindMenuItemLabel" />

そして、これはあなたのstyle.xmlです

<style name="behindMenuItemLabel">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_marginLeft">20dp</item>
    <item name="android:layout_marginBottom">4dp</item>
    <item name="android:textSize">30sp</item>
    <item name="android:drawableLeft">@drawable/your_icon</item>
    <item name="android:textColor">#d2d2d2</item>
</style>
于 2013-08-12T10:30:27.920 に答える
2

アイコンに個別の imageView を使用しないでください。テキストビューで、ドローアブルを右(または左、上、下)に設定します

 android:drawableRight="@android:drawable/ic_btn_speak_now"
于 2013-08-12T10:30:34.600 に答える
1

この属性を使用してandroid:drawableLeft="your_drawable_id"テキストの左側に画像を設定すると、xml タグは次のようになります。

<TextView
    android:id="@+id/bookTitle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="center_horizontal"
    android:drawableLeft="@drawable/icon"
    android:text="Item 0"
    style="@style/behindMenuItemLabel"/>

画像を右、上、または下に設定することもできます。幸運をお祈りしています。

于 2013-08-12T10:30:40.623 に答える