【问题标题】:ListView drawableLeft of header view changes position标题视图的 ListView drawableLeft 更改位置
【发布时间】:2015-01-06 22:22:58
【问题描述】:

我将一个布局 ass headerView 附加到我的列表视图中。但是,当我这样做时,它会失去它的风格(即 drawableLeft 改变位置)。

这是标题视图:

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/header"
    style="@style/header"
    android:drawableLeft="@drawable/ic_setup"
    android:text="@string/fragment_contacts"
    android:contentDescription="@string/fragment_contacts"
    android:textSize="@dimen/text_size_medium"
    android:layout_gravity="center_horizontal"
    android:onClick="readMe"
    android:textColor="?attr/color1" />

这就是我将它添加到列表视图的方式

        ((TextView) header).setText(getString(R.string.fragment_favorites));
        listView.addHeaderView(header, null, false);

这是渲染listView并且drawableLeft改变位置时的最终结果:

如何将 DrawableLeft 保持在文本旁边的正确位置?

【问题讨论】:

  • 为什么不使用水平的LinearLayoutImageViewTextView

标签: android listview styles


【解决方案1】:

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal">

    <TextView
        android:id="@+id/YOUR_TEXTVIEW"
        ....
        />

</FrameLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-13
    • 1970-01-01
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多